PNRT
asked on
In VB.Net - Trying to insert variables into MSSQL
Hi Experts, In vb.net I am connecting to a MS SQL 2005 Database and inserting the following-
objCommand = New SqlCommand("Insert Into Bookings(Guest, Bnumber, Cumber) Values(" & " '1', '2', '3')") This works correctly. But when I substitue my variables into the "Values", I get the error message "The name "xxxx" is not valid in this context. I think I'm getting my " " and ' ' mixed up. Please can someone show me the syntax for multiple variables in the SQL command in .net. Thanks in advance
objCommand = New SqlCommand("Insert Into Bookings(Guest, Bnumber, Cumber) Values(" & " '1', '2', '3')") This works correctly. But when I substitue my variables into the "Values", I get the error message "The name "xxxx" is not valid in this context. I think I'm getting my " " and ' ' mixed up. Please can someone show me the syntax for multiple variables in the SQL command in .net. Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, you should not wrap INTEGERS, not strings. See example above.
ASKER
Sorry, the 1 2 and 3 were just example variables, not integers.
But your solution worked first time
Many Thanks
But your solution worked first time
Many Thanks