开发者

Datatable add to dataset

i need to set a table to a dataset

DataSet ds = EventDal.GetEvents();
DataSet dsReturn = new DataSet();
DataTable dtReturn = dsReturn.Tables.Add();
dtReturn.Columns.Add(开发者_如何转开发"id");
dtReturn.Columns.Add("description");
dtReturn.Columns.Add("status");

foreach (DataRow row in ds.Tables[0].Rows)
{
  if(Convert.ToInt32(row[1]) == status )
  {
    DataRow newrowdata = dtReturn.NewRow();
    dsReturn.Tables["dtReturn"].ImportRow((row));///i'm getting object ref not set to an instance of object..
    //DataRow drReturn = dtReturn.NewRow();
    //dsReturn.Tables["dtReturn"].Rows.Add(row);
  }
}
return dsReturn;


DataSet customerOrders = new DataSet("CustomerOrders");

DataTable ordersTable = customerOrders.Tables.Add("Orders");

DataColumn pkOrderID = 
    ordersTable.Columns.Add("OrderID", typeof(Int32));
ordersTable.Columns.Add("OrderQuantity", typeof(Int32));
ordersTable.Columns.Add("CompanyName", typeof(string));

ordersTable.PrimaryKey = new DataColumn[] { pkOrderID };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜