错误_ in_ c#_Mysql [英] Errors_ in_ c#_Mysql

查看:54
本文介绍了错误_ in_ c#_Mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试插入查询:它显示(You can''t insert null value for this column)此错误如何解决此问题;但是我正在通过单击按钮传递所有列的值.
我试过以下两个查询,它显示相同的错误:(那三列数据类型是varchar)
听到是我的编码;

I am trying insert query:It showing (You can''t insert null value for this column)This Error How can i solve this problem;But i am passing value for all columns throug button click.
I tried following both query it''s showing same error:(That three columns data type is varchar)
Hear is my coding;

string date=datetimepicker1.value.tostring("dd-MM-yyyy")

查询类型一:

Query type one:

"insert into curculars values('"+ textBox3.Text + "','"+ date +"','"+comboBox5.Text +")'"

查询类型二:

Query Type Two:

Insert into curculars(curc,date1,whom)values(@val1,@val2,@val3)





cmd.mysqlparametter.add(new mysqlparametter("val1",textbox3.text));
cmd.mysqlparametter.add(new mysqlparametter("val2",date));
cmd.mysqlparametter.add(new mysqlparametter("val3",combobox5.text));

推荐答案

默认日期格式MySql是``YYYY-MM-DD''

更改您的
Default date format of MySql is ''YYYY-MM-DD''

Change your
string date=datetimepicker1.value.tostring("dd-MM-yyyy")




to

string date=datetimepicker1.value.tostring("yyyy-MM-dd")



然后尝试插入


如果要将MySQL日期的格式从YYYY-MM-DD更改为MM/DD/YYYY或DD/MM/YYYY格式,可以使用DATE_FORMAT()函数,如下例所示:




then try to insert


If you wanted to change the format of a MySQL date from YYYY-MM-DD to MM/DD/YYYY or DD/MM/YYYY format you can use the DATE_FORMAT() function as shown in the example below:


SELECT DATE_FORMAT(CURDATE(), ''%d/%m/%Y'')




OR

SELECT DATE_FORMAT(CURDATE(), ''%m/%d/%Y'')


这篇关于错误_ in_ c#_Mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆