在VB.NET/SQL中执行存储过程时,是否应该添加"EXEC"?

When executing stored procedures in VB.NET/SQL, are we supposed to add "EXEC" or not?

我不知道该相信什么了。当我们 运行ning 我们的 VB.NET SqlCommand 关闭存储过程时,我们是否在我们的命令中添加 EXEC?!

我收到一个错误:

Could not find stored procedure 'EXEC uspGrabAutoByYMM'.

但是其他人告诉我你必须把 EXEC 放在那里才能 运行。

这是我的示例代码:

Public Sub BindGridAutosYMM()
    Dim constring As String = "server=classified;database=classified"
    Using con As New SqlConnection(constring)
        Using cmd As New SqlCommand("EXEC uspGrabAutoByYMM", con)
            cmd.Parameters.Add("@Year", SqlDbType.VarChar).Value = TextBox1.Text
            cmd.Parameters.Add("@Make", SqlDbType.VarChar).Value = TextBox2.Text
            cmd.Parameters.Add("@Model", SqlDbType.VarChar).Value = TextBox3.Text
            cmd.CommandType = CommandType.StoredProcedure
            Using sda As New SqlDataAdapter(cmd)
                Using dt As New DataTable()
                    sda.Fill(dt)
                    DataGridView1.DataSource = dt
                End Using
            End Using
        End Using
    End Using
End Sub

没有

System.Data.CommandType.StoredProcedure 为您完成。

会有帮助:How to: Execute a Stored Procedure that Returns Rows

另见:

Using EXECUTE with Stored Procedures You do not have to specify the EXECUTE keyword when you execute stored procedures when the statement is the first one in a batch.

EXECUTE (Transact-SQL)

如果您删除 "exec" 而问题仍然存在,请确认您的数据库中存在此过程。