Click here to Skip to main content
15,914,165 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
C#
string date=datetimepicker1.value.tostring("dd-MM-yyyy")
Query type one:
C#
"insert into curculars values('"+ textBox3.Text + "','"+ date +"','"+comboBox5.Text +")'"
Query Type Two:
SQL
Insert into curculars(curc,date1,whom)values(@val1,@val2,@val3)


C#
cmd.mysqlparametter.add(new mysqlparametter("val1",textbox3.text));
cmd.mysqlparametter.add(new mysqlparametter("val2",date));
cmd.mysqlparametter.add(new mysqlparametter("val3",combobox5.text));
Posted
Updated 21-Sep-11 1:23am
v3
Comments
Prerak Patel 20-Sep-11 23:27pm    
Added code block.

1 solution

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")


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')
 
Share this answer
 
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900