Gladimir
Well-known member
Im having a little trouble getting with DataRows and DataRowCollections. The primary question is at the bottom of this post.
Here is a code snippet that is working well:
The above code pulls assetID from the scsdComputers table and searches for it in the asset table. If the assetID is not found in the asset table, the assetID is added to the asset table in the if-block.
The trouble comes in the else-block. If the assetID does exist in the asset table, then I want to edit a value in the row returned by the Select method used one line above the if-block. However, I noticed there seems to be some difference between DataRow[] and DataRow, and that seems to be what I need to know.
I cannot add foundRows.BeginEdit() to my else-block because the BeginEdit method does not exist for DataRow[] foundRows. Do I have to create a new DataRowCollection and re-run my Select method in the else-block using DataRow?
Here is a code snippet that is working well:
Code:
// code is truncated for brevity;
DataRowCollection drcComputer = ds1.Tables["scsdComputer"].Rows;
foreach (DataRow row in drcComputer)
{
// search for assetID from computer table in asset table
string strrowSelect = "assetID = " + strassetID + "";
DataRow[] foundRows = ds1.Tables["asset"].Select(strrowSelect);
// if assetID does not exist in asset table, then add it
if (foundRows.Length < 1)
{
// add new row
DataRow newRow = ds1.Tables["asset"].NewRow();
newRow["assetID"] = strassetID;
ds1.Tables["asset"].Rows.Add(newRow);
}
else
{
// NOTE: this is where I am having problems
}
}
The above code pulls assetID from the scsdComputers table and searches for it in the asset table. If the assetID is not found in the asset table, the assetID is added to the asset table in the if-block.
The trouble comes in the else-block. If the assetID does exist in the asset table, then I want to edit a value in the row returned by the Select method used one line above the if-block. However, I noticed there seems to be some difference between DataRow[] and DataRow, and that seems to be what I need to know.
I cannot add foundRows.BeginEdit() to my else-block because the BeginEdit method does not exist for DataRow[] foundRows. Do I have to create a new DataRowCollection and re-run my Select method in the else-block using DataRow?