Edit: I now see the similarities. Thank you for the question to reference.
I am trying to insert a new row into a test table where the id column is a uniqueidentifier. I have generated a guid (userID) however, it will not pass along into SQL. I always get the error "syntax error around "
Is it my syntax of how I entered userID into the SQL query or am I just going about this completely the wrong way.
I have the following code:
cnn = new SqlConnection(connectionString);
cnn.Open();
Guid userID = Guid.NewGuid();
string sql;
sql = "INSERT INTO test (id, column1, column2) VALUES ("+@userID+",222,333)";
command = new SqlCommand(sql, cnn);
try
{
command.ExecuteNonQuery();
MessageBox.Show("success!");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}