我已经搜索了 evreywhere 并尝试了所有建议,但在运行以下代码时仍然没有运气。请注意,某些代码已被注释掉。那只是我尝试不同的事情。
SqlConnection connection = new SqlConnection("数据源=URB900-PC\SQLEXPRESS;初始目录=usersSQL;集成安全=True");
string password = PasswordTextBox.Text;
string email = EmailTextBox.Text;
string firstname = FirstNameTextBox.Text;
string lastname = SurnameTextBox.Text;
//command.Parameters.AddWithValue("@UserName", username);
//command.Parameters.AddWithValue("@Password", password);
//command.Parameters.AddWithValue("@Email", email);
//command.Parameters.AddWithValue("@FirstName", firstname);
//command.Parameters.AddWithValue("@LastName", lastname);
command.Parameters.Add("@UserName", SqlDbType.VarChar);
command.Parameters["@UserName"].Value = username;
command.Parameters.Add("@Password", SqlDbType.VarChar);
command.Parameters["@Password"].Value = password;
command.Parameters.Add("@Email", SqlDbType.VarChar);
command.Parameters["@Email"].Value = email;
command.Parameters.Add("@FirstName", SqlDbType.VarChar);
command.Parameters["@FirstName"].Value = firstname;
command.Parameters.Add("@LasttName", SqlDbType.VarChar);
command.Parameters["@LasttName"].Value = lastname;
SqlCommand command2 = new SqlCommand("INSERT INTO users (UserName, Password, UserEmail, FirstName, LastName)" +
"values (@UserName, @Password, @Email, @FirstName, @LastName)", connection);
connection.Open();
command2.ExecuteNonQuery();
//command2.ExecuteScalar();
connection.Close();
当我运行它时,填写文本框并点击我得到的按钮......
必须声明标量变量“@UserName”。
任何帮助将不胜感激。谢谢。