By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,588 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,588 IT Pros & Developers. It's quick & easy.

Updating datatable using datatable.rows.find()

P: n/a
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.


Apr 25 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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[i];
}
}
anyone ??

Lars E

"Lars E" <la***********@infocare.no> skrev i melding
news:em**************@TK2MSFTNGP02.phx.gbl...
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.


Apr 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.