void BindDataGridView() { string strErr = ""; DataTable objDataTable = new DataTable(); string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Teacher.Teacher objTea = new Manage.Teacher.Teacher(strConnection); int iRent = objTea.SearchTea(out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { dataGridView1.DataSource = objDataTable; } }
private void menuSearchTea_Click(object sender, EventArgs e) { string strErr = ""; DataTable objDataTable = new DataTable(); string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Teacher.Teacher objTea = new Manage.Teacher.Teacher(strConnection); string strTeaNo = txtTeaNo.Text; strTeaNo = strTeaNo.Replace("%", @"\%"); strTeaNo = strTeaNo.Replace("_", @"\_"); strTeaNo = strTeaNo.Replace("'", @"\''"); strTeaNo = strTeaNo.Trim(); string strTeaName = txtTeaName.Text; strTeaName = strTeaName.Replace("%", @"\%"); strTeaName = strTeaName.Replace("_", @"\_"); strTeaName = strTeaName.Replace("'", @"\''"); strTeaName = strTeaName.Trim(); if (iRight != 3) { int iRent = objTea.SearchTea(strTeaNo, strTeaName, out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { if (objDataTable.Rows.Count == 0) { MessageBox.Show("没有符合你要查询的记录"); } else { dataGridView1.DataSource = objDataTable; } txtTeaName.Text = ""; txtTeaNo.Text = ""; } } else { int iRent = objTea.StuSearchOneTeaNo(strTeaNo, strTeaName, strUserNo, out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { if (objDataTable.Rows.Count == 0) { MessageBox.Show("没有符合你要查询的记录"); } else { dataGridView1.DataSource = objDataTable; } txtTeaName.Text = ""; txtTeaNo.Text = ""; } } }