G
Guest
I have a need in my application to add a dummy row to a dataset object after
I have filled it with a call to the database. Trying to find a solution I
thought that doing a dataset merge might work, however its doesn't seem to
be. Following examples I found in some MSDN articles I came up with the
following code:
DataSet ds = new DataSet();
DataSet dsTemp = new DataSet();
DataRow dr;
DataTable dt = new DataTable("tempTable");
DataColumn dc = new DataColumn("VALUE",Type.GetType("System.String"));
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("TEXT",Type.GetType("System.String"));
dt.Columns.Add(dc1);
dr = dt.NewRow();
dr["VALUE"] = "test";
dr["TEXT"] = "test";
dt.Rows.Add(dr);
dsTemp.Tables.Add(dt);
dsTemp.AcceptChanges();
ds = functionThatReturnsData();
ds.Merge(dsTemp);
return ds;
In the above example, my expectations where that ds would contain both its
data and the data from dsTemp. However it only contains the data returned
from the db call. If I switch it around to: dsTemp.Merge(ds), dsTemp only
contains its original data and nothing from ds.
Am I just missing something here or am I way off base?
thanks
I have filled it with a call to the database. Trying to find a solution I
thought that doing a dataset merge might work, however its doesn't seem to
be. Following examples I found in some MSDN articles I came up with the
following code:
DataSet ds = new DataSet();
DataSet dsTemp = new DataSet();
DataRow dr;
DataTable dt = new DataTable("tempTable");
DataColumn dc = new DataColumn("VALUE",Type.GetType("System.String"));
dt.Columns.Add(dc);
DataColumn dc1 = new DataColumn("TEXT",Type.GetType("System.String"));
dt.Columns.Add(dc1);
dr = dt.NewRow();
dr["VALUE"] = "test";
dr["TEXT"] = "test";
dt.Rows.Add(dr);
dsTemp.Tables.Add(dt);
dsTemp.AcceptChanges();
ds = functionThatReturnsData();
ds.Merge(dsTemp);
return ds;
In the above example, my expectations where that ds would contain both its
data and the data from dsTemp. However it only contains the data returned
from the db call. If I switch it around to: dsTemp.Merge(ds), dsTemp only
contains its original data and nothing from ds.
Am I just missing something here or am I way off base?
thanks