0
我搜索evreywhere並嘗試所有建議,但運行下面的代碼時仍然沒有運氣。請注意,一些代碼已被註釋掉。那只是我嘗試不同的事情。 SqlConnection connection = new SqlConnection(「Data Source = URB900-PC \ SQLEXPRESS; Initial Catalog = usersSQL; Integrated Security = 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();
當我運行此,填寫文本框,然後按下按鈕,我得到......
必須聲明標量變量「@用戶」。
任何幫助將不勝感激。謝謝。
哎呀。謝謝你的回覆podiluska。我一直在努力掙扎幾個小時。有時候,答案就是盯着你。 – user1642318