我在注册页面上有几个文本框和一些下拉列表。当用户按下提交时,我希望验证值,如果它们是正确的,我想在数据库中输入它们。即使我手动调用验证并检查它们是否有效,我的值仍未验证。所以我的代码将空的东西放在DB中......
protected void btn_registreren_Click(object sender, EventArgs e)
{
Validate();
if (Page.IsValid)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Server.MapPath(@"\App_Data") + @"\Database11.accdb";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO Gebruikers(gebruikersnaam, geboortedatum, admin, wachtwoord) VALUES (@gebruikersnaam, @geboortedatum, @admin, @wachtwoord)";
cmd.Parameters.AddWithValue("@gebruikersnaam", txt_email.Text);
cmd.Parameters.AddWithValue("@geboortedatum", txt_dag.Text + "-" + ddl_maand.SelectedValue + "-" + txt_jaar.Text);
cmd.Parameters.AddWithValue("@admin", false);
cmd.Parameters.AddWithValue("@wachtwoord", txt_wachtwoord.Text);
try
{
conn.Open();
lblConnState.Text = "Connection is: " + conn.State.ToString();
cmd.ExecuteNonQuery();
}
catch (Exception exc)
{
lblConnState.Text = exc.Message;
}
finally
{
conn.Close();
lblConnState2.Text = "<br />Connection is: " + conn.State.ToString();
}
}
else
{
lblConnState2.Text = "not valid";
}
}
我尝试过:给所有字段,验证器和提交按钮提供相同的验证组。我也尝试在页面加载中执行此操作。也在互联网上广泛浏览,但无法找到问题所在。