我是菜鸟,想问如何将日期型的数据存入数据库?
我是菜鸟,想问如何将日期型的数据存入数据库?
例如:
string sql = "insert into bb_gbdjb (xm,xb,mz,jg,rdsj)values( ' " + textBox1.Text + " ', ' " + comboBox2.Text + " ', ' " + comboBox1.Text + " ', ' " + textBox5.Text + " ', ' " + dateTimePicker2.MaxDate + " ') ";
rdsj为datetime型,我用的是dateTimePicker控件。但存如数据库的结果为9998-12-31,而不是2007-01-01,是不是dateTimePicker2.MaxDate 错了?
------解决方案--------------------dateTimePicker2.value
------解决方案--------------------你要的是当前时间,而不是最大时间。
Value
------解决方案--------------------是啊,为什么不用Data而用MaxData呢?
改成DateTimePicker2.Value就可以了.
------解决方案--------------------dateTimePicker1.Value.ToString( "yyyy-MM-dd ")
------解决方案--------------------dateTimePicker2.MaxDate 最大时间
------解决方案--------------------dateTimePicker1.Value.ToString( "yyyy-MM-dd ")
------解决方案--------------------dateTimePicker1.Value.ToString( "yyyy-MM-dd ")
对头
------解决方案--------------------string sql = "insert into bb_gbdjb (xm,xb,mz,jg,rdsj)values( ' " + textBox1.Text + " ', ' " + comboBox2.Text + " ', ' " + comboBox1.Text + " ', ' " + textBox5.Text + " ', ' " + dateTimePicker2.MaxDate + " ') ";
这样写不是好习惯.
string xm = textBox1.Text;
string xb = comboBox2.Text;
string mz = comboBox1.Text;
string jg = textBox5.Text;
string rdsj =dateTimePicker1.value.ToString( "YYYY-MM-DD ");
string sql = "insert into bb_gbdjb (xm,xb,mz,jg,rdsj)values( ' " + xm + " ', ' " + xb + " ', ' " + mz + " ', ' " + jg + " ', ' " + rdsj + " ') ";
------解决方案--------------------dateTimePicker1.Value.ToString( "yyyy-MM-dd ")
------解决方案--------------------dateTimePicker不是很好用,如果需要更好的和我联系!