what is datatable,you mean table running on server?

解决方案 »

  1.   

    if as i have said
    you can use sqldatareader
    while(sdr.Read())
    {
    TableRow tr=new TableRow();
    TableCell tc1=new TableCell();
    TableCell tc2=new TableCell();
    tc1.Text=sdr.GetValue(0).ToString();
    if(sdr.Read())
    tc2.Text=sdr.GetValue(0).ToString();
    tr.Cells.Add(tc1);
    tr.Cells.Add(tc2);
    this.Table1.Rows.Add(tr);
    }
      

  2.   

    string strSql = "SELECT * FROM table1";
    SqlConnection cn = new SqlConnection(数据库连接字符串);
    SqlDataAdapter da = new SqlDataAdapter(strSql,cn);
    DataTable dt = new DataTable();
    da.Fill(dt);DataGrid1.DataSource = dt.DefaultView;
    DataGrid1.DataBind();
      

  3.   

    示例代码:SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");SqlCommand selectCMD = new SqlCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn);
    selectCMD.CommandTimeout = 30;SqlDataAdapter custDA = new SqlDataAdapter();
    custDA.SelectCommand = selectCMD;nwindConn.Open();DataSet custDS = new DataSet();
    custDA.Fill(custDS, "Customers");nwindConn.Close();