insert datetime value in sql database with c#

后端 未结 8 1781
死守一世寂寞
死守一世寂寞 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:14

     DateTime time = DateTime.Now;              // Use current time
     string format = "yyyy-MM-dd HH:mm:ss";    // modify the format depending upon input required in the column in database 
     string insert = @" insert into Table(DateTime Column) values ('" + time.ToString(format) + "')"; 
    

    and execute the query. DateTime.Now is to insert current Datetime..

提交回复
热议问题