Reputation: 11
I have visual studio 2008. I am using vb.net to add data to table in the in-built sql server. I am unable to add data to multi-column tables. I can add data to single column tables but if I add more columns to the table and then associated textboxes to the form, the code throws "Column name or number of supplied values does not match to table definition" error.
Upvotes: 1
Views: 606
Reputation: 6849
If u going to execute insert query then you must have specified values for each column.
For example
Insert Into TableName (Column1,Column2,Column3,Column4)Values(1, 'Value1', '2014-01-01', NULL);
if the number of values and number of specified column does not match then sql will shows the error like "Column name or number of supplied values does not match to table definition"
if you are joining values from textbox to your query then you must have specified NULL
value if textbox is blank or specify default value
Dim _SQL As String = string.Empty
_SQL = "Insert Into TableName (Column1,Column2,Column3,Column4)Values("
IF TextBox1.Text != String.Empty Then
_SQL = TextBox1.Text + ","
Else
_SQL = "NULL,";
Else
''Continue for second value
Upvotes: 1