How to pass an integer value like SQL command parameters?
I am trying like this:
cmd.CommandText = (\"insert_questions \'\" +
cmd.Parameters.AddWith
You don't concatenate the SqlParameter instances; instead:
cmd.CommandText = "insert_questions @store_result, @store_title, @store_des";
cmd.Parameters.AddWithValue("store_result", store_result);
cmd.Parameters.AddWithValue("store_title", store_title);
cmd.Parameters.AddWithValue("store_des", store_des);
The names used in AddWithValue
are used in the TSQL as @store_result
, etc.
If we assume that inert_questions
is actually a proc, then it is even simpler:
cmd.CommandText = "insert_questions";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("store_result", store_result);
cmd.Parameters.AddWithValue("store_title", store_title);
cmd.Parameters.AddWithValue("store_des", store_des);
Alternatively, if all of that seems tedious, tools like dapper-dot-net make this easier:
someOpenConnection.Execute("insert_questions",
new { store_result, store_title, store_des },
commandType: CommandType.StoredProcedure);