将c#的datetimepicker值存储到mysql数据库中
作者:互联网
您好,我想将datetimepicker值存储到mysql数据库中,我的代码如下
dtpDate = datetimepicker1.value.date;
dtpTime = datetimepicker2.value.Timeofday;
MySqlCommand cmd = new MySqlCommand("INSERT INTO schedule_days(schedule_name,start_time,status,days,start_date,connector_id) VALUES ('" + name + "','" + dtpTime + "','" + s + "','" + day + "','"+dtpDate+"','" + chkArray[i].Tag + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
但是没有值存储在数据库中
那个地方无法读取数据.
可能是什么问题?
解决方法:
在MySQL数据库中未输入值,因为在dtpTime和dtpDate字段中的查询中有错误.
您大喊大叫,将其替换为dtpTime.Value.TimeofDay和dtpDate.Value.Date,新的查询将像这样
dtpDate = datetimepicker1.value.date;
dtpTime = datetimepicker2.value.Timeofday;
MySqlCommand cmd = new MySqlCommand("INSERT INTO schedule_days(schedule_name,start_time,status,days,start_date,connector_id) VALUES ('" + name + "','" + dtpTime.Value.TimeofDay + "','" + s + "','" + day + "','"+dtpDate.Value.Date.ToString("yyyy-MM-dd HH:mm")+"','" + chkArray[i].Tag + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
标签:c,datetimepicker 来源: https://codeday.me/bug/20191031/1973754.html