我试图运行查询以将数据插入数据库,但是在运行代码时出现错误..
ExecuteNonQuery 需要一个开放且可用的连接。连接的当前状态为关闭。
你能告诉我错误是什么以及为什么会发生吗?
{
con2.Open();
if (TextBox1.Text == "")
{
Response.Write("<script>alert('please enter Login Name')</script>");
}
else if (TextBox2.Text == "")
{
Response.Write("<script>alert('please enter Password')</script>");
}
else if (TextBox3.Text == "")
{
Response.Write("<script>alert('please enter Confirm Password')</script>");
}
else
{
//if (TextBox2.Text == TextBox3.Text)
//{
string a;
a = "insert into tbl_Purchase_Users(Login_Name, Password, Uname, Uid, EmailID, Role, Status) values(@LName, @Pswd, @Uname, @uid, @Eid, @role, @stat)";
SqlCommand cm = new SqlCommand(a, con1);
cm.Parameters.AddWithValue("@LName", TextBox1.Text);
string original;
original = TextBox2.Text.Trim();
int h = original.GetHashCode();
string withHash = original;
b1 = Encoding.BigEndianUnicode.GetBytes(withHash);
encrypted = Convert.ToBase64String(b1);
cm.Parameters.AddWithValue("@Pswd", encrypted);
cm.Parameters.AddWithValue("@Uname", TextBox3.Text);
cm.Parameters.AddWithValue("@uid", TextBox4.Text);
cm.Parameters.AddWithValue("@Eid", TextBox5.Text);
cm.Parameters.AddWithValue("@role", TextBox6.Text);
cm.Parameters.AddWithValue("@stat", TextBox7.Text);
cm.ExecuteNonQuery();
Response.Write("<Script>alert('inserted')</script>");
}
con2.Close();
}