【发布时间】:2018-06-03 15:50:42
【问题描述】:
直接查询和存储过程有什么区别吗?
[下面]
我有这个查询 6 年,因为现在我在一家公司工作了 7 个月,我在使用这个查询的 .net 应用程序中使用 Select *Update* delete Insert
如果这是存储过程或直接查询或其他任何内容,我不知道它会调用什么,但输出是相同的
<WebMethod()> _
Public Function add(ByVal firstname As String, ByVal lastname As String)
Dim con As SqlConnection
Dim com As SqlCommand
con = New SqlConnection(cstring)
con.Open()
com = New SqlCommand("SELCT * FROM NewSalestbl where Firstname = @Firstname and Lastname= @Lastname", con)
com.Parameters.AddWithValue("@Firstname", firstname)
com.Parameters.AddWithValue("@Lastname", lastname)
Dim reader As SqlDataReader = com.ExecuteReader
While reader.Read
status = reader("Lastname").ToString
End While
MsgBox("Inserted")
con.Close()
Return status
End Function
我想知道创建查询时最好的程序是什么?
[下]
我现在尝试使用此代码
Dim con As SqlConnection
Dim com As New SqlCommand
con = New SqlConnection(cstring)
con.Open()
com.CommandText = "searchtest"
com.CommandType = CommandType.StoredProcedure
com.Connection = con
com.Parameters.AddWithValue("@firstname", TextBox1.Text)
Dim raeder As SqlDataReader
raeder = com.ExecuteReader
While raeder.Read
MsgBox(raeder(1))
End While
如果这两个示例相同或不同,谁能向我解释一下 TIA
【问题讨论】:
标签: sql-server vb.net stored-procedures