gridview显示不出数据怎么办

来源:百度知道 编辑:UC知道 时间:2024/06/04 10:09:16
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.Text.ToString().Trim();
string d = this.DropDownList2.Text.ToString().Trim();
string sql = "select 图书编号,图书名,分类,作者,出版社 from 图书信息表 where 图书名 like '%"+a+"%' or 作者 like '%"+b+"%' or 分类 like '%"+c+"%' or 出版社 like '%"+ d +"%' ";
SqlDataAdapter sda = new SqlDataAdapter(sql, Sql);
sda.Fill(dt);
Sql.Close();
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
这是我的代码,可是按了button之后,可以弹出gridview,但是里面没有数据的显示,按不同类型检索,可以得到行数不同的gridview,就是显示

<asp:BoundField DataField="图书编号" HeaderText="图书编号" />

肯能是2个方面的问题,一是,你没有给gridview控件绑定数据,二你可以在查询分析器中查看你的sql语句有没有值!