1     public int CheckUserName(string username) 
2 {
3 DBClass db = new DBClass();
4 int a;
5 using (SqlConnection conn = db.GetConn())
6 {
7 SqlCommand cmd = new SqlCommand("select count(*) from tb_Member111 where id = '" + username + "'", conn);
8 a = Convert.ToInt32(cmd.ExecuteScalar());
9 conn.Close(); //关闭后再返回,否则返回值永远是0
10 return a;
11 }
12 }


把SqlConnection关闭再返回才是关键!!

相关文章:

  • 2021-12-28
  • 2021-06-08
  • 2022-12-23
  • 2021-08-07
  • 2021-05-26
  • 2022-12-23
  • 2021-06-25
  • 2022-01-12
猜你喜欢
  • 2021-06-13
  • 2021-06-11
  • 2022-12-23
  • 2021-11-16
  • 2021-06-28
  • 2021-09-23
相关资源
相似解决方案