What does the @ do in the following statement?
-
What does the @ do in the following statement? Is this used to pick the particular DB field associated with the row in the update statement? Dim strSQL As String = _ "UPDATE [Products] SET [ProductName] = @ProdName, " & _ "[UnitPrice] = @UnitPrice, [ProductDescription] = @ProdDesc, [LastUpdated] = @LastUpdated " & _ "WHERE [ProductID] = @ProductID"
-
What does the @ do in the following statement? Is this used to pick the particular DB field associated with the row in the update statement? Dim strSQL As String = _ "UPDATE [Products] SET [ProductName] = @ProdName, " & _ "[UnitPrice] = @UnitPrice, [ProductDescription] = @ProdDesc, [LastUpdated] = @LastUpdated " & _ "WHERE [ProductID] = @ProductID"
That's SQL stored procedure syntax. The items with '@' in front refer to parameters being supplied to a stored procedure. The only reason you should ever see this in VB code is if the code is attempting to create the stored procedure on the SQL Server - I can't see that this would ever work if you attempt to run it as an update statement directly from a VB app. It's possible that someone's copied and pasted the code from a stored procedure directly into VB as an attempt to do an update, but I don't believe it can possibly work.
-
What does the @ do in the following statement? Is this used to pick the particular DB field associated with the row in the update statement? Dim strSQL As String = _ "UPDATE [Products] SET [ProductName] = @ProdName, " & _ "[UnitPrice] = @UnitPrice, [ProductDescription] = @ProdDesc, [LastUpdated] = @LastUpdated " & _ "WHERE [ProductID] = @ProductID"
-
That's SQL stored procedure syntax. The items with '@' in front refer to parameters being supplied to a stored procedure. The only reason you should ever see this in VB code is if the code is attempting to create the stored procedure on the SQL Server - I can't see that this would ever work if you attempt to run it as an update statement directly from a VB app. It's possible that someone's copied and pasted the code from a stored procedure directly into VB as an attempt to do an update, but I don't believe it can possibly work.
Craster wrote:
The items with '@' in front refer to parameters being supplied to a stored procedure.
Among other things. See also Guffa's reply to the Original Poster.
Craster wrote:
The only reason you should ever see this in VB code is if the code is attempting to create the stored procedure on the SQL Server - I can't see that this would ever work if you attempt to run it as an update statement directly from a VB app.
This is incorrect.
Craster wrote:
It's possible that someone's copied and pasted the code from a stored procedure directly into VB as an attempt to do an update, but I don't believe it can possibly work.
Yes, it can work. You pass parameters for any SQL Statement through the SqlCommand object. For example. The SQL:
SELECT * FROM MyTable WHERE name=@name
Can be accessed in VB as:
Dim cmd As SqlCommand
cmd = New SqlCommand()
cmd.CommandText="SELECT * FROM MyTable WHERE name=@name"
cmd.Parameters.Add("@name", "John Smith")
cmd.Connection = MyConnection
Dim reader As SqlDataReader
reader = cmd.ExecuteReader()ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?