-1
我是绝对的初学者,我解决不了的问题,收到错误&例外是在必须在Insert语句声明标量变量“@UserId”
objCommand.ExecuteNonQuery();
异常消息抛出:“ 必须声明标量变量@userId。“
private void btnRegister_Click(object sender, EventArgs e)
{
if (tbxUserName.Text == "" || tbxPassword.Text == "")
{
MessageBox.Show("Please enter values!");
return;
}
string strConnection;
strConnection = ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString;
SqlConnection objConnection = new SqlConnection();
objConnection.ConnectionString = strConnection;
objConnection.Open();
string strSQL;
SqlCommand objCommand = new SqlCommand("SELECT * FROM LoginTable WHERE UserId='" + tbxUserName.Text + "';", objConnection);
SqlDataAdapter objAdapter = new SqlDataAdapter();
objAdapter.SelectCommand = objCommand;
objAdapter.Fill(objDataSet);
int i = objDataSet.Tables[0].Rows.Count;
if (i > 0)
{
MessageBox.Show("User Name " + tbxUserName.Text + " already exists");
tbxPassword.Text = "";
objDataSet.Clear();
}
else
{
strSQL = "INSERT INTO LoginTable(UserId, Password) VALUES(@UserId, @Password)";
objCommand.Parameters.AddWithValue("@UsesrId", tbxUserName.Text);
objCommand.Parameters.AddWithValue("@Password", tbxPassword.Text);
objCommand.CommandText = strSQL;
objCommand.ExecuteNonQuery();
objConnection.Close();
message = "Registered Successfully! " + "Welcome " + tbxUserName.Text;
this.Hide();
WelcomeForm wf = new WelcomeForm(message);
wf.Show();
}
}
只是近距离投票这样的问题。 – 2014-12-01 19:32:53
谢谢Atilla Ozgur – 2014-12-01 20:01:30