简体   繁体   中英

How can i get rid of this c# error

this is my error.

There are more 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.

this is my code

string conn = WebConfigurationManager.ConnectionStrings["dbconn"].ConnectionString;
            SqlConnection myConnection = new SqlConnection(conn);
            myConnection.Open();
            SqlCommand cmd = new SqlCommand("insert into Register(Email,Username,Password,Confirm_Password) values('" + txtEmail.Text + "','" + txtUsername.Text + "''" + Password.Text + "''" + ConfirmPassword.Text + "')", myConnection);
            cmd.ExecuteNonQuery();
            myConnection.Close();

can somebody please help me?

thanks in advance!!!

You're missing 2 commas in that line.

SqlCommand cmd = new SqlCommand("insert into Register(Email,Username,Password,Confirm_Password) values('" + txtEmail.Text + "','" + txtUsername.Text + "','" + Password.Text + "','" + ConfirmPassword.Text + "')", myConnection);

But as comments indicated you really should consider using parameterized queries. Also I can suggest EntitiyFramework too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM