ExecuteNonQuery 要求已打开且可用的连接。连接的当前状态为已关闭。
protectedvoidbtn_addUser_Click(objectsender,System.EventArgse){if((this.txtPnum.Text=...
protected void btn_addUser_Click(object sender, System.EventArgs e)
{
if ((this.txtPnum.Text == "") || (this.TxtAname.Text == "") || (this.Txtname.Text == "") || (this.Txtpwd2.Text == "") || (this.Txtpwd1.Text == ""))
{
Page.RegisterStartupScript("", "<script>alert('输入内容不能为空')</script>");
}
else
{
string UserPnum = this.txtPnum.Text.Trim().ToString();
string str = ConfigurationSettings.AppSettings["con"];
string select = "select * from users where u_Pnum='" + UserPnum + "'";
SqlConnection con = new SqlConnection(str);
SqlDataAdapter sda = new SqlDataAdapter(select, con);
DataSet ds = new DataSet();
sda.Fill(ds);
int UserPoliceNum = ds.Tables[0].Rows.Count;
con.Close();
if (UserPoliceNum > 0)
{
Page.RegisterStartupScript("", "<script>alert('此警号已被使用,请输入正确的警号!')</script>");
}
else
{
if (Txtpwd1.Text != Txtpwd2.Text)
{
Page.RegisterStartupScript("", "<script>alert('两次密码输入不一致')</script>");
}
else
{
string insret = "insert into users(u_Pnum,u_Aname,u_name,u_pwd,u_power) values('" + this.txtPnum.Text + "','" + this.TxtAname.Text + "','" + this.Txtname.Text + "','" + this.Txtpwd2.Text + "','" + this.ddl_power.SelectedItem + "')";
SqlConnection con1 = new SqlConnection(str);
con1.Open();
SqlCommand cmd = new SqlCommand(insret, con);
cmd.ExecuteNonQuery();
Page.RegisterStartupScript("", "<script>alert('添加成功')</script>");
con1.Close();
}
}
} 展开
{
if ((this.txtPnum.Text == "") || (this.TxtAname.Text == "") || (this.Txtname.Text == "") || (this.Txtpwd2.Text == "") || (this.Txtpwd1.Text == ""))
{
Page.RegisterStartupScript("", "<script>alert('输入内容不能为空')</script>");
}
else
{
string UserPnum = this.txtPnum.Text.Trim().ToString();
string str = ConfigurationSettings.AppSettings["con"];
string select = "select * from users where u_Pnum='" + UserPnum + "'";
SqlConnection con = new SqlConnection(str);
SqlDataAdapter sda = new SqlDataAdapter(select, con);
DataSet ds = new DataSet();
sda.Fill(ds);
int UserPoliceNum = ds.Tables[0].Rows.Count;
con.Close();
if (UserPoliceNum > 0)
{
Page.RegisterStartupScript("", "<script>alert('此警号已被使用,请输入正确的警号!')</script>");
}
else
{
if (Txtpwd1.Text != Txtpwd2.Text)
{
Page.RegisterStartupScript("", "<script>alert('两次密码输入不一致')</script>");
}
else
{
string insret = "insert into users(u_Pnum,u_Aname,u_name,u_pwd,u_power) values('" + this.txtPnum.Text + "','" + this.TxtAname.Text + "','" + this.Txtname.Text + "','" + this.Txtpwd2.Text + "','" + this.ddl_power.SelectedItem + "')";
SqlConnection con1 = new SqlConnection(str);
con1.Open();
SqlCommand cmd = new SqlCommand(insret, con);
cmd.ExecuteNonQuery();
Page.RegisterStartupScript("", "<script>alert('添加成功')</script>");
con1.Close();
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询