是因为button还有一些其他操作数据库的功能
Default3.aspx
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox2.Text == "" || TextBox3.Text == "")
{
Response.Write("<script defer>alert('请输入专业ID与名称!');</script>");
return;
}
if (Request["action"] == "edit")
{
string strCmd = "update lab_major set dept_id='" + DropDownList1.SelectedValue + "',major_ID='" + TextBox2.Text + "',major_name='" + TextBox3.Text + "' where major_num like '" + Request["majornum"] + "";
co_major_add.ENQ(strCmd);
}
else
{
string strC = "select * from lab_major where major_id like'" + TextBox2.Text + "' or major_name like'" + TextBox3.Text + "'";
object a = co_major_add.EXS(strC);
if (a == null)
{
string strCmd1 = "insert lab_major (major_id,major_name,dept_ID) values('" + TextBox2.Text + "','" + TextBox3.Text + "','" + DropDownList1.SelectedValue + "')";
co_major_add.ENQ(strCmd1);
Response.Write("<script defer>alert('添加成功!');</script>");
}
else
{
Response.Write("<script defer>alert('您输入的已存在,请重新输入!');</script>");
}
}
string str1 = "<script language='javascript'>window.dialogArguments.document.location.href='Major.aspx';window.close();</script>";
Response.Write(str1);
}