我已经进行了验证,以防止在数据库为空时将数据插入数据库,但它仍然向数据库输入空白表单?
protected void Button1_Click(object sender, EventArgs e)
{
ProjectTestEntities User_save = new ProjectTestEntities();
User ins = new User();
ins.name = TextBox1.Text;
ins.email = TextBox2.Text;
ins.phone = TextBox3.Text;
ins.gender = RadioButtonList1.SelectedValue;
ins.password = TextBox4.Text;
if (ins.name == null || ins.email == null || ins.gender == null || ins.password == null)
{
Label1.Text = "Incomplete input";
}
else
{
User_save.Users.AddObject(ins);
User_save.SaveChanges();
}
}