qq_34684363 2016-06-12 04:15 采纳率: 0%
浏览 1400
已结题

asp.net+sql禁止插入重复值

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>");
}

}

我想加一条约束

就是在同一时间、同一教室不能有两场考试
如果加入了重复值 提示添加失败 重新添加
如果不重复 提示添加成功

谢谢各位大神

  • 写回答

4条回答 默认 最新

  • devmiao 2016-06-12 04:21
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试