Sql server 在VB.NET/SQL中执行存储过程时,是否应该添加;执行官;还是不?
我不知道该相信什么了。当我们在存储过程之外运行VB.NETSql server 在VB.NET/SQL中执行存储过程时,是否应该添加;执行官;还是不?,sql-server,vb.net,stored-procedures,Sql Server,Vb.net,Stored Procedures,我不知道该相信什么了。当我们在存储过程之外运行VB.NETSqlCommand时,我们是否在命令中添加EXEC 我得到一个错误: 找不到存储过程“EXEC uspGrabAutoByMM” 但其他人告诉我,你必须把EXEC放进去,它才能运行 以下是我的示例代码: Public Sub BindGridAutosYMM() Dim constring As String = "server=classified;database=classified" Using con As N
SqlCommand
时,我们是否在命令中添加EXEC
我得到一个错误:
找不到存储过程“EXEC uspGrabAutoByMM”
但其他人告诉我,你必须把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.StoredProcess为您完成此操作
这将有助于:
参见:
与存储过程一起使用EXECUTE
当语句是批处理中的第一个语句时,执行存储过程时不必指定EXECUTE关键字
如果删除“exec”后问题仍然存在,请确认数据库中存在此过程。否在此上下文中不需要添加exec。如果添加时出现错误,并且省略时没有出现错误,则听起来您已经找到了答案。当你能够演示代码时,“其他人”告诉你的并没有多大区别。我完全明白你的意思。我完全明白你的意思。哈哈,当我告诉人们我在VB中用@符号编写SQL代码,人们告诉我将其存储在SQL SSM中时,我的哲学也是如此?好像没什么区别一样!!:DMaybe这些人可能不理解您试图执行过程的上下文。在本例中,您已经给出了
SqlCommand
一个提示,说明它是一个存储过程,因此它可以处理EXEC
部分本身。@Cᴏ哦,在这种情况下,我不得不加上它。事先,我会运行这个程序,它会说“我们找不到参数@Year,所以程序已经中止了”,没有这条线会是原因吗?