C#GridView無法显示查询结果
前台代码:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4"
ForeColor="#333333" GridLines="None"
OnRowDeleting="GridView1_RowDeleting"
OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="客户编号" ReadOnly="True"/>
<asp:BoundField DataField="Master_Name" HeaderText="客户姓名" />
<asp:BoundField DataField="Master_address" HeaderText="客户地址" />
<asp:BoundField DataField="Master_tel" HeaderText="客户电话" />
<asp:BoundField DataField="Mark" HeaderText="备注" />
<asp:CommandField HeaderText="选择" ShowSelectButton="True" />
<asp:CommandField HeaderText="编辑" ShowEditButton="True" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="true" />
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="true" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="true" ForeColor="White" />
</asp:GridView>
后台BUTTON代码:
string sqlstr = "select id ,master_name ,master_address ,master_tel ,mark from master where master_name like '" + tbx_select_name.Text + "' and master_tel like '" + tbx_select_tel.Text + "'";
sqlcon=new OleDbConnection(strcon);//strcon定义的语句为:string strcon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\data\\HMS.mdb";
OleDbDataAdapter myda = new OleDbDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds,"表");
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[]{ "id"};
GridView1.DataBind();
sqlcon.Close();
SQL在ACCESS里直接是查的出来数据的。为什么结果不显示在GRIDVIEW里,请救,谢谢!
------解决方案--------------------
你把like换成等号试试,like一般需要配合% _这类通配符的。