/// <summary> /// 查询字符串: /// </summary> private void GetMajorName() { /// /// 老方法 /// //构造查询字符串 //string sql = "select name from major"; //MySqlDataAdapter mda = new MySqlDataAdapter(sql, DBHelper.MySQLStr); //设置XXX //DataSet ds = new DataSet(); //mda.Fill(ds, "MajorName"); //DataView dv = new DataView(); //dv = ds.Tables["student"].DefaultView; //MessageBox.Show(dv.ToString()); /// /// 新方法 /// StudentDataProvider sdp = new StudentDataProvider("select major_name from ms_major", "MajorName"); DataSet ds = sdp.GetRawData(); if (ds.Tables["MajorName"].Rows.Count > 0) { foreach (DataRow row in ds.Tables[0].Rows) { //Console.WriteLine(row[0].ToString()); MajorLstSource.Add(row[0].ToString()); } } else { MessageBox.Show("数据表为空!"); } }
private DataTable Show() { DataTable dt = new DataTable(); try { //尝试构造拼接sql语句 //List<string> whereList = new List<string>(); //List<SqlParameter> paramsList = new List<SqlParameter>(); //if (MajorList.ItemsSource.ToString() != "全部") //{ // whereList.Add("major_name=@MajorName"); // paramsList.Add(new SqlParameter("@MajorName", MajorList.SelectedItem)); //} //if (GradeList.ItemsSource.ToString() != "全部") //{ // whereList.Add("grade_name=@GradeName"); // paramsList.Add(new SqlParameter("@GradeName", GradeList.SelectedItem)); //} //string whereSql = string.Join(" and ", whereList); //if (MajorList.ItemsSource.ToString() != "全部") //{ // whereList.Add("name=@MajorName"); // paramsList.Add(new SqlParameter("@MajorName", MajorList.Text)); //} //if (GradeList.ItemsSource.ToString() != "全部") //{ // whereList.Add("name=@GradeName"); // paramsList.Add(new SqlParameter("@GradeName", GradeList.Text)); //} //string whereSql = string.Join(" and ", whereList); ////StudentDataProvider sdp = new StudentDataProvider("select stu_number,stu_name,name,class_name,ban_num,dor_num from major,class,student_new,dormitory,ban where stu_dormitory=dor_id and stu_class=class_id and dor_ban=ban_id and class.major_id=major.major_id"); ////DataSet ds = sdp.GetRawData(); //string sql = "select stu_num,student.name,class.name,building.num,dormitory.num from school,major,class,student,dormitory,building"; //if (whereSql.Length > 0) //{ // sql = sql + whereSql; //} //StudentDataProvider sdp = new StudentDataProvider("select stu_number,stu_name,major_name,class_name,ban_num,dor_num from major,class,student_new,dormitory,ban where stu_dormitory=dor_id and stu_class=class_id and dor_ban=ban_id and class.major_id=major.major_id"); //DataSet ds = sdp.GetRawData(); //string sql = "select stu_number,stu_name,major_name,class_name,ban_num,dor_num from major,class,student_new,dormitory,ban where stu_dormitory=dor_id and stu_class=class_id and dor_ban=ban_id and class.major_id = major.major_id and "; //if (whereSql.Length > 0 && whereSql != null) //{ // sql = sql + whereSql; //} string sql = "select stu_number,stu_name,major_name,class_name,ban_num,dor_num from school_major,class,student_new,dormitory,ban where stu_dormitory=dor_id and stu_class=class_id and dor_ban=ban_id and class.major_id=major.major_id"; StudentDataProvider sdp = new StudentDataProvider(sql, "Show"); DataSet ds = sdp.GetRawData(); ///MySqlDataAdapter mda = new MySqlDataAdapter(sql, DBHelper.MySQLStr); //DataSet ds = new DataSet(); //string sql = "select stu_number,stu_name,major_name,class_name,ban_num,dor_num from school_major,school_class,student_new,stu_dormitory,stu_building where stu_dormitory=dor_id and stu_class=class_id and dor_ban=ban_id and class.major_id=major.major_id"; //if (whereSql.Length > 0) //{ // sql = sql + whereSql; //} //mda.Fill(ds, "Show"); dt = ds.Tables["Show"]; } catch (Exception ex) { MessageBox.Show(ex.Message); } return dt; }