private void AcceptChanges()
{
   DataSet myDataSet;
   myDataSet = new DataSet();   // Not shown: methods to fill the DataSet with data.
   DataTable t;
   t = myDataSet.Tables["Suppliers"];   // Add a DataRow to a table.
   DataRow myRow;
   myRow = t.NewRow();
   myRow["CompanyID"] = "NWTRADECO";
   myRow["CompanyName"] = "NortWest Trade Company";   // Add the row.
   t.Rows.Add( myRow );   // Calling AcceptChanges on the DataSet causes AcceptChanges to be
   // called on all subordinate objects.
   myDataSet.AcceptChanges();
}

解决方案 »

  1.   

    ds.Tables["page"].Rows.Add(rs);//这里应该是添加DataRow
      

  2.   

    to:一瓢
    加数组就不可以吗?必须加datarow?
      

  3.   

    ds.Tables["page"].Rows是一个集合,DataRow是集合中的一员,
    属性值
    包含 DataRow 对象的 DataRowCollection;否则为空值(如果不存在任何 DataRow 对象)。备注
    若要创建新的 DataRow,必须使用 NewRow 方法返回新对象。这样的对象将按照架构自动配置,该架构是通过 DataColumn 对象的集合为 DataTable 定义的。在创建新行并为行中每个列设置值之后,使用 Add 方法将该行添加到 DataRowCollection 中。集合中的每个 DataRow 表示表中的一行数据。若要提交对行中某一列的值的更改,必须调用 AcceptChanges 方法。示例
    [Visual Basic, C#, C++] 下面显示两个返回和设置行的示例。第一个示例使用 Rows 属性,并为每一行打印每一列的值。第二个示例使用 DataTable 对象的 NewRow 方法创建具有 DataTable 的架构的新 DataRow 对象。在设置行值之后,通过 Add 方法将该行添加到 DataRowCollection 中。[Visual Basic] 
    Private Sub PrintRows(myDataSet As DataSet)
        ' For each table in the DataSet, print the values of each row.
        Dim thisTable As DataTable
        For Each thisTable In  myDataSet.Tables
            ' For each row, print the values of each column.
            Dim myRow As DataRow
            For Each myRow In  thisTable.Rows
                Dim myCol As DataColumn
                For Each myCol In  thisTable.Columns
                    Console.WriteLine(myRow(myCol))
                Next myCol
            Next myRow
        Next thisTable
    End Sub
       
       
    Private Sub AddARow(ds As DataSet)
        Dim t As DataTable
        t = ds.Tables("Suppliers")
        ' Use the NewRow method to create a DataRow with the table's schema.
        Dim newRow As DataRow = t.NewRow()
        ' Set values in the columns:
        newRow("CompanyID") = "NewCompanyID"
        newRow("CompanyName") = "NewCompanyName"
        ' Add the row to the rows collection.
        t.Rows.Add(newRow)
    End Sub[C#] 
    private void PrintRows(DataSet myDataSet){
       // For each table in the DataSet, print the values of each row.
     
       foreach(DataTable thisTable in myDataSet.Tables){
          // For each row, print the values of each column.
          foreach(DataRow myRow in thisTable.Rows){
             foreach(DataColumn myCol in thisTable.Columns){
                Console.WriteLine(myRow[myCol]);
             }
           }
       }
    }
      

  4.   

    to:一瓢
    myDataSet.AcceptChanges();
    我还是不明白acceptChanges()有什么用?和add()有什么区别?
    还有就是不用往table里加columns吗?直接用row["name"]不可以吧?       
                                ds.Tables.Add("page");
    ds.Tables["page"].Columns.Add("name");
    ds.Tables["page"].Columns.Add("content");
    ds.Tables["page"].Columns.Add("date");
      

  5.   

    还是不成;
    ds.Tables["page"].Rows[7]["name"]为"username"datagrid1.datasource=ds.tables["page"].defaultview而DataGrid1.Items[7].Cells[0].Text为什么是""
    DataGrid1.Items[7].Cells[1].Text和DataGrid1.Items[7].Cells[1].Text不存在
      

  6.   

    我想你没有必要copy表一次啊,直接使用ds.Tables[0].defaultview来绑定就行啊。你之所以DataGrid1.Items[0].Cells[2].Text获取不到数据,我想是因为你使用模板列来绑定数据?如果是的话,肯定是不能这样获取数据的,要用FindControl方法来获取数据。所以如果想使用DataGrid1.Items[0].Cells[2].Text来得到数据就不能使用模板列。
      

  7.   

    可是问题是:我怎么通过findcontrol的到第一行和最后一行的数据值?
    我一页显示8个数据,怎么弄呢?
      

  8.   

    我怎么通过findcontrol的到第一行和最后一行的数据值?
    我一页显示8个数据,怎么弄呢?