I have the following statements:
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["DataBaseName"]);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "update Table1 set data = @data where id = @id";
cmd.Parameters.AddWithValue("@data", SqlDbType.VarChar).Value = data;
cmd.Parameters.AddWithValue("@id", SqlDbType.Int).Value = id;
cmd.CommandType = CommandType.Text;
try
{
DataSet ds = new DataSet();
con.Open();
cmd.Prepare();
cmd.ExecuteNonQuery();
return true;
}
When executing cmd.Prepare()
I have an error SqlCommand.Prepare method requires all parameters to have an explicitly set type
I read some answers here, but looks like I did as described here but still have the same problem.
What am I missing?