C#
private void DataGridToBind()
{
string Type;
string Key;
string sql;
Type=Request.QueryString["type"];
Key=Request.QueryString["key"];
OleDbConnection con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="+Request.PhysicalApplicationPath + System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
sql="select pname,typename,product.id from product,type where product.type1=type.type1  and pname like '*"+Key+"*'"+Type;
OleDbDataAdapter sda=new OleDbDataAdapter();
sda.SelectCommand=new OleDbCommand(sql,con);
DataSet ds=new DataSet();
sda.Fill(ds);
this.DataGrid1.DataSource=ds.Tables[0];
this.DataGrid1.DataBind();
}
aspx:<TD class="medium13" align="center" bgColor="#ffffff" valign="top">
<asp:DataGrid id="DataGrid1" runat="server" Width="440px" AutoGenerateColumns="False" Font-Size="Larger"
HorizontalAlign="Center" GridLines="None">
<ItemStyle Height="24px"></ItemStyle>
<HeaderStyle HorizontalAlign="Center" Height="28px"></HeaderStyle>
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="id" DataNavigateUrlFormatString="showdailp.aspx?cid={0}" DataTextField="pname" HeaderText="产品名称">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<FooterStyle HorizontalAlign="Left"></FooterStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="typename" HeaderText="产品类别">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</TD>
问题是数据不显示,但调示的时候,把SQL语句放在ACCESS的SQL分析器,有数据显示的(当然值是传对了的),而且有所有的程序都可通过,就是绑定不出数据(显示只有脑datagrid1的头)!请各位高手帮忙看看,不甚感激!!!

解决方案 »

  1.   

    ds.Tables[0];里面有数据没?设个断点看看
      

  2.   

    <asp:DataGrid id="DataGrid1" runat="server" Width="440px" AutoGenerateColumns="False" Font-Size="Larger这个地方面要加一个 key=id之类的要不就用sqldatasoure
      

  3.   

    lz还是一步一步调试一下吧,那边问题就知道了。比如你的Request.QueryString["key"];是不是传的值,数据库中根本就没有呢,一步一步调调看
      

  4.   

    Type=Request.QueryString["type"];
    Key=Request.QueryString["key"];
    这两个的值传过过来了的!
      

  5.   

    page_load
    if(!page.IsPostBack)
    {
        DataGridToBind();}
      

  6.   

    sql="select pname,typename,product.id from product,type where product.type1=type.type1  and pname like '*"+Key+"*'"+Type;
    在看看这个语句是不是有错误
      

  7.   

    select pname,typename,product.id from product,type where product.type1=type.type1  and pname like '*卡*' and product.type1=1
    以上是调试过程中的SQL语句,在分析器中可能查出数据的!急!郁闷了好久了!
      

  8.   

    因为*号是在ACCESS表示所有,%号SQL SERVER中表示所有的
    ===========这个简单的道理我当然知道.
    但用oledb访问的时候就不是这样了.