哪个高手能帮忙写一段Gridview组件中显示数据的代码

来源:百度知道 编辑:UC知道 时间:2024/06/14 08:12:54
就是 下面花括号中间的部分...从数据库中把数据读出来,显示在控件里
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

}

private void BindGrid()
{
string myConnection = "server=localhost;database=图书馆;uid=sa;pwd=123456";
SqlConnection Sql = new SqlConnection(myConnection);
Sql.Open();
DataTable dt = new DataTable();
string a = this.TextBox1.Text.ToString().Trim();
string b = this.TextBox2.Text.ToString().Trim();
string c = this.DropDownList1.SelectedItem.Text.ToString().Trim();
string d = this.DropDownList2.SelectedItem.Text.ToString().Trim();
string sql = "select 图书编号,图书名,分类,作者,出版社 from 图书信息表 where 图书名 like '%" + a + "%' and 作者 like '%" + b + "%' and 分类 like '%" + c + "%' and 出版社 like '%" + d + "%' ";
SqlDataAdapter sda = new SqlDataAdapter(sql, Sql);
sda.Fill(dt);

//判断是否有记录
//dt.Rows.Count == 0
Sql.Close();