I'm using a SQL Server database and Windows Forms application. I have 2 textboxes and 1 combobox. Users inputs their name and working rate into the textboxes and they chose year from combobox. I try to insert those values into my database.
EX:
2018 Mike 39,72 WORKERS
In database:
year --> nvarchar(4)
name --> nvarchar(50)
rate --> decimal(18,2)
type --> nvarchar(50)
My code is like:
SqlCommand cmd = new SqlCommand("INSERT INTO USERS(YEAR,NAME,RATE,TYPE) VALUES ('" + yearcombo.Text + "','" + name.Text + "','" + Convert.ToDecimal(rate.Text, CultureInfo.CurrentCulture) + ",'" + "WORKERS" + "')", connection);
I get this error:
There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
nvarchar(4)?!?!?! Use the most appropriate datatype - always - and here this would definitely be anINT(more than anvarchar(4)) ....