SqlConnection myConnection = new SqlConnection("server=localhost;uid=sa;pwd=;database=test");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Titles order by id desc", myConnection);
myConnection.open();
DataSet ds = new DataSet();
myCommand.Fill(ds, "Titles");
myConnection.close();
DataGrid1.DataSource = ds.Tables["Titles"].DefaultView;
DataGrid1.DataBind();

解决方案 »

  1.   

    you do not need to open SqlConnection specifically if you use SqlDataAdapterdid you hook up Page_Load with Page's Load event?
      

  2.   

    不要open的呀,可能原因是数据表中没有数据!
      

  3.   

    数据库里肯定是有数据的,我也觉得用了SqlDataAdapter后就不用用open了。那位大虾看出是什么问题了吗?
      

  4.   

    跟总你的ds,看看ds.tables(0).rodws.count是否为0。
    不要open的不是这个写法。
      

  5.   

    trymyCommand.Fill(ds);
    DataGrid1.DataSource = ds.Tables[0].DefaultView;
    DataGrid1.DataBind();
      

  6.   

    加一个myconnection.open()试一下吧