/// <summary> /// 获取数据集 /// </summary> /// <param name="sql"></param> /// <returns>DataSet GetDataset</returns> public DataSet GetDataset(string sql, string tablename) { try { DataSet ds = new DataSet(); string strConn = Dblink.connstr(); SqlConnection conn = new SqlConnection(strConn); SqlCommand command = new SqlCommand(sql, conn); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = command; int i = adapter.Fill(ds, tablename); if (i == 0) { return(null); } else { return(ds); } } catch { return(null); } }
/// <summary> /// 水晶报表的数据集 /// </summary> /// <param name="sql"></param> /// <param name="table"></param> /// <returns>DataSet GetDatasetReport</returns> public DataSet GetDatasetReport(string sql, string table) { try { DataSet ds = new DataSet(); //string strConn = "server=(local);database =Library;integrated security=true"; string strConn = Dblink.connstr(); SqlConnection conn = new SqlConnection(strConn); SqlCommand command = new SqlCommand(sql, conn); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = command; int i = adapter.Fill(ds, table); if (i == 0) { return(null); } else { return(ds); } } catch { return(null); } }
/// <summary> /// 下拉形式显示数据 /// </summary> /// <param name="Sql">Sql 语句</param> /// <param name="field">字段名</param> /// <param name="name">ComboBox名称</param> public void ShowInfoList(string Sql, string field, ComboBox name) { try { //SqlConnection conn = new SqlConnection("server=(local);database =Library;integrated security=true"); string constr = Dblink.connstr(); SqlConnection conn = new SqlConnection(constr); SqlDataAdapter da = new SqlDataAdapter(Sql, conn); //SqlCommandBuilder cb = new SqlCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds); name.DataSource = ds.Tables[0]; //以下拉的形式显示所有用户名 name.DisplayMember = field; conn.Close(); } catch (Exception) { ; } }