i have 3 text boxes for insert data into database but out of 3 text boxes only two textboxes to be used for insert data ,and 3 rd text box must be empty but in database it should shows null.
i wrote some code but display a error like syntax error near ','
Wim SturkenboomPosted Oct 25, 2014, 3:47 PM
i wrote some code but display a error like syntax error near ','
[/quote]
show the relevant code and show the exact error message
And you probably need to use DBNull instead of null to achieve this from C#.
Michal HabalcikPosted Oct 25, 2014, 11:11 AM
If (String.IsNullOrEmpty(textbox.Text)) {
INSERT INTO some_table (column1, column2, column3) VALUES (@tb1, @tb2, NULL)
}
else
{
INSERT INTO some_table (column1, column2, column3) VALUES (@tb1, @tb2, textbox.Text)
}
or even a more simple version:
INSERT INTO some_table (column1, column2, column3) VALUES (@tb1, @tb2, String.IsNullOrEmpty(textbox.Text) ? NULL : textbox.Text)
VulpesPosted Oct 25, 2014, 8:30 AM
INSERT INTO some_table (column1, column2, column3) VALUES (@tb1, @tb2, NULL)
where tb1 and tb2 are parameters whose values are (or are based on) textbox1 and textbox2 respectively.