public bool isProc(string procName) { bool isConnected = chkConnection(); if (isConnected) { string sqlIsProc = "select * from sysobjects where xtype='p' and name='" + procName + "'"; SqlCommand comm = new SqlCommand(sqlIsProc, this.Con); comm.CommandType = CommandType.Text; SqlDataReader sdr = comm.ExecuteReader(); if (!sdr.IsClosed) { int i = 0; //判断是否有下一行数据 while (sdr.Read()) { DALUtil.Output(this, "No." + (i++) + " 所查存储过程名为: " + sdr[0]); if (procName.Equals(sdr[0])) { sdr.Close(); return(true); } } } sdr.Close(); return(false); } else { return(false); } }
//检测连接是否打开 public bool chkConnection() { try { if (this.con.State == ConnectionState.Closed) { con.Open(); DALUtil.Output(this, "连接成功"); return(true); } else { return(true); } } catch (Exception e) { DALUtil.Output(this, " " + e.Message); MessageBox.Show("数据库连接失败,请检查该服务相关配置!\n 1.数据库登录名和密码是否正确;\n 2.数据库服务是否配置", "提示", MessageBoxButtons.RetryCancel, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2); } return(false); }
/// <summary> /// 由账号密码查询管理员信息,验证登陆 /// </summary> /// <param name="a">AdminInfo实体</param> /// <returns>查询到的用户信息</returns> public AdminInfo SelectAdminInfo(AdminInfo admininfo) { bool isConn = db.chkConnection(); if (isConn) { string sqlGetAdmin = @"select * from Users where Username = '******' and PassWord = '******'"; DataSet ds = db.ExcuteQuery(sqlGetAdmin); if (ds.Tables[0].Rows.Count > 0) { DALUtil.Output(this, ds.Tables[0].Rows[0][0].ToString()); admininfo.Uid = int.Parse(ds.Tables[0].Rows[0][0].ToString()); return(admininfo); } else { return(null); } } else { return(null); } }