Reputation: 45
I have a sentence follow:
string strSQL = "update pl_poli set ag_vouch = ' ',ag_vdate = #, ag_vmode = null where
pl_no = '" + textBox5.Text + "' and pl_endtno ='" + textBox6.Text + "'";
I can't update because error "data type mismath". i have fill ag_vdate is type date I want to Update it -> null Please can you help me. Thank you so much.
Upvotes: 1
Views: 1306
Reputation: 176896
In your case you cannot pass " # " at datetime column because sql server consider this as varchar value and not able to convert this in datetime so...
Try to do as below
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO table1 (column1, column2) VALUES (@param1, @param2)";
command.Parameters.Add("@param1", SqlDbType.DateTime).Value =
DateTime.TryParse(txtDate.Text, out d) ?
(object)d :
DBNull.Value // inserting NULL
...
connection.Open();
command.ExecuteNonQuery();
}
Upvotes: 1