我正在尝试将字符串“testId”设置为从数据库中选择的值,但收到此错误:
没有为一个或多个必需参数指定值。
当我将代码保持原样时,它可以工作,但是当没有注释掉这些行时,我得到了错误
string testId = "";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void registerButton_Click(object sender, EventArgs e)
{
try
{
string connString = (@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|HorseDB.mdb");
OleDbConnection conn = new OleDbConnection(connString);
conn.Open();
OleDbCommand cmd = conn.CreateCommand();
OleDbCommand cmdSelect = conn.CreateCommand();
cmd.CommandText = @"INSERT INTO [Users]([UserName], [UserSurname], [CellNumber], [Email], [Password])VALUES(@Name, @Surname, @Number, @Email, @Password)";
//cmdSelect.CommandText = @"SELECT [UserId] FROM [Users] WHERE [Email] = @Email";
cmd.Parameters.AddWithValue("@Name", registerNameTexbox.Text);
cmd.Parameters.AddWithValue("@Surname", registerSurnameTextbox.Text);
cmd.Parameters.AddWithValue("@Number", registerNumbertextbox.Text);
cmd.Parameters.AddWithValue("@Email", registerEmailTextbox.Text);
cmd.Parameters.AddWithValue("@Password", registerPasswordTextbox.Text);
cmd.ExecuteNonQuery();
//testId = cmdSelect.ExecuteNonQuery().ToString();
conn.Close();
paymentSite();
}
catch (OleDbException fail)
{
errorLabel1.Text = fail.Message;
}
}