1 public string Admin(string Name,string Pwd) 2 { 3 Admin admin = new Admin(); 4 admin.Name = Name; 5 admin.Pwd = Pwd; 6 string CheckAdmin = "select qx from admin where Name='" +Name + "'and Pwd='" + Pwd + "'"; 7 string returndate=""; 8 SqlConnection conn = new SqlConnection("Server=(local);database=vote;uid=sa;pwd=123456;"); 9 try 10 { 11 conn.Open(); 12 SqlCommand cmd = new SqlCommand(CheckAdmin, conn); 13 if (cmd.ExecuteScalar() is DBNull) 14 { 15 return returndate = "用户名存在"; 16 } 17 else 18 19 return returndate = "用户名不存在"; 20 21 } 22 catch (SqlException ee) 23 { 24 25 return ee.Message.ToString(); 26 } 27 28 29 30 31 }