日期:2014-05-18 浏览次数:20698 次
if (tBT.Text.Trim() != "") { string sql = "select TeacherId,LoginId,LoginPwd,TeacherName,Sex,Birthday from Teacher where TeacherName='"+tBT.Text.Trim()+"'"; //dataAdapter = new SqlDataAdapter(sql, DBHelper.conn); //dataAdapter.Fill(ds, "Teacher"); //ds.Select(sql) in ds.Tables["Teacher"]; } else { MessageBox.Show("请输入教师姓名"); }
private void BindData() { SqlConnection sqlcon = new SqlConnection(); try { sqlcon.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DB_CON"].ConnectionString; sqlcon.Open(); SqlCommand sqlcom = new SqlCommand(); sqlcom.Connection = sqlcon; sqlcom.CommandText = "select ..."; sqlcom.CommandType = CommandType.Text; SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom); ds = new DataSet(); sqlda.Fill(ds); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } catch (Exception ex) { throw (ex); } finally { sqlcon.Close(); } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindData(); } }