public partial class addkao : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] == null)
Response.Redirect("./login.aspx");
if (Session["power"].ToString() != "0")
{
Response.Redirect("error.aspx");
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["kaowuConnectionString"].ToString();
conn.Open();
string str = "insert into js(考室,可容纳人数,课号,参加考试人数,班级,系别,年级,专业,课程名,开始时间,结束时间,主考老师,参考序号) values('" + DropDownList1.Text + "','" + TextBox1.Text + "','" + DropDownList2.Text + "','" + TextBox5.Text + "','" + DropDownList7.Text + "','" + DropDownList4.Text + "','" + DropDownList5.Text + "','" + DropDownList6.Text + "','" + DropDownList3.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox6.Text + "')";
SqlCommand comm = new SqlCommand(str, conn);
comm.ExecuteNonQuery();
conn.Close();
Response.Write("<Script language='javascript'>alert('增加成功!')</script>");
}
}
我想加一条约束
就是在同一时间、同一教室不能有两场考试
如果加入了重复值 提示添加失败 重新添加
如果不重复 提示添加成功
谢谢各位大神