I am getting the following error when trying to use a parameter to insert a value into my SQL Server database.
SqlParameter Param1 = new SqlParameter("@test", SqlDbType.VarChar);
Param1.Value = "test";
SqlCommand AddtoDb = new SqlCommand("INSERT INTO [temp] VALUES (@test)", conn);
AddtoDb.ExecuteNonQuery();
This is the error I get:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
The database has only 1 column that accepts varChar(50). I know the connection is working because the database received the input if I do something like:
SqlCommand AddtoDb = new SqlCommand("INSERT INTO [temp] VALUES ('test')", conn);
AddtoDb.ExecuteNonQuery();
What am I doing wrong?
<pre></pre>tags. You have left out the details that would give us any chance of figuring out what went wrong.