Hi,
I have a table login in sql it contains lots of fields(for example fname,lname,Password,address,Username etc). I need to insert some data only to the table(Username and Password). I use the code in C#
SqlCommand cmd = new SqlCommand("insert into login values(@UserName)", con);
cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
on clicking submit button it shows an error message:
"Column name or number of supplied values does not match table definition"
Please correct the problem.
Loading

Munesh SharmaPosted Mar 25, 2014, 8:36 AM
SqlCommand cmd = new SqlCommand("INSERT INTO tablename (UserName,Password) VALUES(@UserName, @Password)", con);
cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
these username and password should be same as column name which you pass in table.
Abhay ShankerPosted Mar 25, 2014, 9:09 AM
SqlCommand cmd = new SqlCommand("insert into login values(@UserName,@Password)", con);
Brijendra GautamPosted Mar 25, 2014, 8:40 AM
Below is the correct command:
SqlCommand cmd = new SqlCommand("Insert Into login(UserName,Password) values(@UserName,@Password)", con);
cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
Try this.