J
Jesper Stocholm
I have created a method that basically copies rows from one DataSet to
another - the slight problem is just, that it doesn't work exactly as I
thought,
The method looks as this:
private void ConvertDataSetToHashTable(DataSet dataSet_)
{
// m_packageLink is a Hashtable
DataSet newSet = new DataSet();
DataTable table = new DataTable();
long packageId = 0;
int counter = 0;
int counterRows = 0;
foreach (System.Data.DataRow row in dataSet_.Tables[0].Rows)
{
if (!row[11].Equals(DBNull.Value))
{
long pid = Convert.ToInt64(row[11]);
if (pid != packageId)
{
if (counter != 0)
{
newSet.Tables.Add(table);
### DataRow newRow = newSet.Tables[0].Rows[counterRows];
counterRows++;
m_packageLink.Add(packageId,newSet);
}
newSet = new DataSet();
table = new DataTable();
table.ImportRow(row);
packageId = Convert.ToInt64(row[11]);
}
else
{
table.ImportRow(row);
packageId = Convert.ToInt64(row[11]);
}
}
else
{
this.m_packageLink.Add(packageId,table);
dataTable table = new DataTable();
return;
}
counter++;
}
}
The idea is that it runs through the rows in my "mother dataset" and
checks the value of a field. It then adds the rows to another dataset
that is put into a Hashtable for quick access later on.
The problem is that the rows I copy into my new dataset all are empty -
but the rows I copy _from_ have 30 fields in them. If I check the row in
the line marked with ###, the ItemArray of the row is of length 0 - where
it should be 30.
Can any of you guys see, what I am doing wrong?
Thanks,
)
another - the slight problem is just, that it doesn't work exactly as I
thought,
The method looks as this:
private void ConvertDataSetToHashTable(DataSet dataSet_)
{
// m_packageLink is a Hashtable
DataSet newSet = new DataSet();
DataTable table = new DataTable();
long packageId = 0;
int counter = 0;
int counterRows = 0;
foreach (System.Data.DataRow row in dataSet_.Tables[0].Rows)
{
if (!row[11].Equals(DBNull.Value))
{
long pid = Convert.ToInt64(row[11]);
if (pid != packageId)
{
if (counter != 0)
{
newSet.Tables.Add(table);
### DataRow newRow = newSet.Tables[0].Rows[counterRows];
counterRows++;
m_packageLink.Add(packageId,newSet);
}
newSet = new DataSet();
table = new DataTable();
table.ImportRow(row);
packageId = Convert.ToInt64(row[11]);
}
else
{
table.ImportRow(row);
packageId = Convert.ToInt64(row[11]);
}
}
else
{
this.m_packageLink.Add(packageId,table);
dataTable table = new DataTable();
return;
}
counter++;
}
}
The idea is that it runs through the rows in my "mother dataset" and
checks the value of a field. It then adds the rows to another dataset
that is put into a Hashtable for quick access later on.
The problem is that the rows I copy into my new dataset all are empty -
but the rows I copy _from_ have 30 fields in them. If I check the row in
the line marked with ###, the ItemArray of the row is of length 0 - where
it should be 30.
Can any of you guys see, what I am doing wrong?
Thanks,
