修改DataTable表
添加一个DataRow到DataTable表的第一行,再绑定

解决方案 »

  1.   

    好象不行,我用insertAt(oRow,0)加到首行,但是它还在最后出现,就象有add(oRow)一个样
      

  2.   

    可以先在DataTable中插入一行,在将DataTable绑定到datagrid中
      

  3.   

    我的代码,你大概看一下
    print ds = new print();
    this.sqlConnection1.Open();
    string strSel = "Select * from s_basic where s_id="+chk_s_id;
    SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,sqlConnection1);
    MyAdapter.Fill(ds,"s_basic");
    //s_family填充空行
    MyAdapter.SelectCommand.CommandText="Select * from s_family where s_id="+chk_s_id;
    MyAdapter.Fill(ds,"s_family");this.sqlCommand1.CommandText = "Select count(*) as iCount from dbo.s_family where s_id="+chk_s_id;
    this.sqlCommand1.Connection =this.sqlConnection1 ;
    SqlDataReader reg=this.sqlCommand1.ExecuteReader();
    reg.Read ();
    int Count=Convert.ToInt32(reg["iCount"]);
    reg.Close ();
    DataRow newRow;
    for(int i=0;i<(6-Count);i++)
    {
    newRow=ds.Tables["s_family"].NewRow();
    newRow["s_ID"]=chk_s_id;
    ds.Tables["s_family"].Rows.Add(newRow);
    }MyAdapter.SelectCommand.CommandText="Select * from s_change where s_id="+chk_s_id;
    MyAdapter.Fill(ds,"s_change");
      

  4.   

    在ROWS对象下,好象没有AddAt(oRow,0)这个方法,是不是写错了?
      

  5.   

    to netwalking(不懂就问) 
    你的做法也是加到最后呀,我不想重构一个DS,有没有更好的方法?
      

  6.   

    在DataTable中添加一列,作为索引。