Updating datatable using datatable.rows.find()

L

Lars E

Hi all

I have a small problem.

I have a datatable with 8 columns. But it is only data in 5 of the columns.
Data for the remaing 3 columns is in another dataset.
I Want to run trough the datatable and fill out the remaining data.

My code so far:
if (this.fetch("custinfo", "fetchCustInfo", out customers, parameters))
{
//Create a datatable for the the combined tables to be view in a
datagridview
DataTable dtCustInfo = new DataTable("CustInfo");
//Fill this datatables with customers.
dtCustInfo = customers.Tables[0];
//Adding field phonenumber. Will get value from custcont later
DataColumn dcPhone = dtCustInfo.Columns.Add("cc-telephone",
typeof(Int32));
dcPhone.AllowDBNull = true;
dcPhone.Unique = false;
//Adding field faxnumber. Will get value from custcont later
DataColumn dcFax = dtCustInfo.Columns.Add("cc-faxnr", typeof(Int32));
dcPhone.AllowDBNull = true;
dcPhone.Unique = false;
//Adding field e-mail. Will get value from custcont later
DataColumn dcEmail = dtCustInfo.Columns.Add("cc-mail", typeof(Int32));
dcPhone.AllowDBNull = true;
dcPhone.Unique = false;

//Run trough the table and populate the new fields
for(int i=0;i< dtCustInfo.Rows.Count;i++)
{
//PROBLEM....I want to find the row in custoerms.Tables[1] with
the primary value in the field c-custno1 in dtCustInfo datatable
DataRow foundRow =
customers.Tables[1].Rows.Find(dtCustInfo.Rows[0]["c-custno1"]);
if (foundRow != null)
{
//modifiy the 3 fields with data fra det dataset
//dtCustInfo.Columns.Add(
}
}

customerDataGridView.DataSource = dtCustInfo;


Please help if you can.



Thank you very much.

Lars E.
 
L

Lars E

Hi again.

i figured out something..... I must use the datatable.select method to find
the record in the other table.
But how can i update each row in current table?

code:
//Run trough the table and populate the new fields
for(int i=0;i< dtCustInfo.Rows.Count;i++)
{
string sStr = "'cc-custnr1' = '" + dtCustInfo.Rows[0]["c-custno1"] + "' AND
'cc-custnr2' = '" + dtCustInfo.Rows[0]["c-custno2"] + "' AND 'cc-class' =
'a'";
DataRow[] foundRow = dtCustCont.Select(sStr);
if (foundRow != null)
{
//here i want to update the fiels "cc-custno1","cc-custno2" and "cc-class"
in datatable "dtCustInfo". HOW?
DataRow currentRow = dtCustInfo.Rows;
}
}


anyone ??

Lars E
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top