insert datetime value in sql database with c#

后端 未结 8 1770
死守一世寂寞
死守一世寂寞 2020-11-30 05:29

How do I insert a datetime value into a SQL database table where the type of the column is datetime?

8条回答
  •  旧巷少年郎
    2020-11-30 06:01

    Convert the existing DateTime object to a string with single quotes around it. I don't think it really matters what format it is, as long as it is valid.

    Something like this:

    string data = "'" + date.ToString() = "'";
    

    Optionally you can create a new format and pass it as a parameter to data.ToString(format);

提交回复
热议问题