3
Reply

How to insert only selected data to table?

Renjith V S

Renjith V S

Mar 25 2014 8:25 AM
1.2k
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.

Answers (3)