62,025
社区成员
发帖
与我相关
我的任务
分享
protected bool IsExist(string classNo,string classJxb)
{
SqlConnection con = new SqlConnection("Server=.;database=TJUT实验室管理;uid=sa;pwd=;");
con.Open();
SqlCommand cmd = new SqlCommand("select * from ClassTB where ClassNo='" + classNo.Replace("'", "''") + "'and ClassJXB='" + classJxb.Replace ("'","''") + "'", con);
System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
return dr.HasRows;
}
if (IsExist (DropDownListClassNo.Text.ToString(),TbJXB.Text.ToString())
{
//做存在的事情
}
else
{
//如果不存,做的事情
}
protected void TbJXB_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Server=.;database=TJUT实验室管理;uid=sa;pwd=;");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from ClassTB where ClassNo='" + DropDownListClassNo.Text.ToString() + "'and ClassJXB='" + TbJXB.Text.ToString() + "'", con);
Int32 count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
SqlDataReader dd = cmd.ExecuteReader();
if (dd.Read())
{
this.LbClassTime.Text = (string)dd.GetSqlString(3);
this.LbClassTime.DataBind();
}
}
else
{
RequiredFieldValidator3.IsValid = false;
}
con.Close();
}