protected void Button1_Click(object sender, EventArgs e) { SqlConnection conn = BaseClass.DBCon(); conn.Open(); SqlCommand cmd = new SqlCommand("select count(*) from tb_homework where StuNo='" + Session["ID"] + "' and ChapTitle='" + DropDownList1.SelectedValue.ToString() + "'", conn); int i = Convert.ToInt32(cmd.ExecuteScalar()); if (i > 0) { Response.Write("<script language=javascript>alert('您已提交作业!')</script>"); } else { string Time = System.DateTime.Now.ToString(); string No = Session["ID"].ToString(); string Content = TextBox1.Text; string Chap = DropDownList1.SelectedValue.ToString(); Homework homework = new Homework(); homework.Add(Time, No, Content, Chap); TextBox1.Text = ""; } }