1

I want to add a Timestamp data in my table but got error how can I fix this?

enter image description here

Here is my Proc

    CREATE PROCEDURE `db`.`AddMerchantProcessor` (m_id INT, p_id INT, d TIMESTAMP)
BEGIN
    INSERT INTO `tbl_merchant_processor`(`merchant_id`, `processor_id`, `date`) VALUES(m_id, p_id, d);
END

1 Answer 1

2

timestamp should be wrap with single quotes, eg

CALL AddMerchantProcessor(0, 1, '2012-01-01 00:00:00')

but it's not the proper way of using the Command object. The query should be parameterized.

Here's a little code snippet:

MySqlCommand comm = new MySqlCommand();
comm.Connection = cn;
comm.CommandType = CommandType.StoredProcedure;
comm.CommandText = "AddMerchantProcessor";
comm.Parameters.AddWithValue("m_id", m_id);
comm.Parameters.AddWithValue("p_id", p_id);
comm.Parameters.AddWithValue("d", d);
cn.Open();
comm.ExecuteNonQuery();

you need to:

  • use using statement for automatic object disposal
  • put some trycatch for proper exception handling

SOURCES

Sign up to request clarification or add additional context in comments.

2 Comments

I tried this already and still got error "Incorrect datetime value: '12/28/2012 17:36:19' for column 'd' at row 1"
it's fix , I just added Convert.ToDateTime(d). Thanks

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.