1

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.

1

1 Answer 1

1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.