Is there any difference between direct querying and stored procedure?
[Below]
I have this query for 6 years because now I'm 7 months employed in a company, I use Select
*Update*
delete
Insert
in .net application using this query
I don't know what it calls if this was a store procedure or a direct query or whatsoever but the output is the same
<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
I want to know what is the best procedure to make when it comes to creating querys?
[BELOW]
I try to use this code now
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
can anyone explain this to me if this two examples are the same or not TIA