473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Comparing 2 datatables...

Hello All,

I am working on a vb.net app where I need to compare to 2 datatables
and determine if a string exists in one or both. The first dt is
filled from the db. A form is loaded and the appropriate items in a
checkedlist box are selected based on the dt. So far, no problem. Then
user can then edit the values in the checkedlist box and choose to
save changes. When they save changes, I throw the new values of the
checked items from the checklistbox into a new dt and compare the two.
Posed a similar question a couple of weeks ago, and was going to try a
comparison based on a datarow but was stymied because the 2 dt's don't
match. Any help will be greatly apprecitated!
Here is some code:

For i = 0 To myDSOrig.Tables(0).Rows.Count - 1
For z = 0 To dsChanged.Tables(0).Rows.Count - 1
If myDSOrig.Tables(0).Rows(i).Item(5).ToString =
dsChanged.Tables(0).Rows(z).Item(5).ToString Then
Exit For
Else
lblChg = New Label
lblChg.Text = myDSOrig.Tables(0).Rows(i)(5)
...
End If
Next z
Next i

This little routine works fine if more than 1 string does not match.
However, if only 1 string doesn't match, then it fails by capturing
the unequal string twice and one string that does match! ie:

TIA,
Dan
Jan 31 '06 #1
5 13337
Frank,

Was it you wich I asked why you did not use a Find (there are two and you
can use both for this).

Although a simple dataview with a datarowfilter containing a builded string
with Or will probably as well do the job.

And than you have the possibility with the datatable.select.

I think that I in this case would go for the dataview with a rowfilter.

http://msdn.microsoft.com/library/de...iltertopic.asp

While I would build that expression with a stringbuilder

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

"Frank" <noreply@nospam> schreef in bericht
news:pa********************************@4ax.com...
Hello All,

I am working on a vb.net app where I need to compare to 2 datatables
and determine if a string exists in one or both. The first dt is
filled from the db. A form is loaded and the appropriate items in a
checkedlist box are selected based on the dt. So far, no problem. Then
user can then edit the values in the checkedlist box and choose to
save changes. When they save changes, I throw the new values of the
checked items from the checklistbox into a new dt and compare the two.
Posed a similar question a couple of weeks ago, and was going to try a
comparison based on a datarow but was stymied because the 2 dt's don't
match. Any help will be greatly apprecitated!
Here is some code:

For i = 0 To myDSOrig.Tables(0).Rows.Count - 1
For z = 0 To dsChanged.Tables(0).Rows.Count - 1
If myDSOrig.Tables(0).Rows(i).Item(5).ToString =
dsChanged.Tables(0).Rows(z).Item(5).ToString Then
Exit For
Else
lblChg = New Label
lblChg.Text = myDSOrig.Tables(0).Rows(i)(5)
...
End If
Next z
Next i

This little routine works fine if more than 1 string does not match.
However, if only 1 string doesn't match, then it fails by capturing
the unequal string twice and one string that does match! ie:

TIA,
Dan

Jan 31 '06 #2

Cor,

Thanks for the response. As a daily lurker here, I can appreciate all
the help you dole out.

Just to make certain I understand your response: I could (should)
create two dataviews and then compare them to see if they are equal?

Also, I am not sure what Find method you are referring to.

In the meantime, I will do some research on the datatable.Select for
more info.

Thanks again!!!

Dan

On Tue, 31 Jan 2006 20:16:32 +0100, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:
Frank,

Was it you wich I asked why you did not use a Find (there are two and you
can use both for this).

Although a simple dataview with a datarowfilter containing a builded string
with Or will probably as well do the job.

And than you have the possibility with the datatable.select.

I think that I in this case would go for the dataview with a rowfilter.

http://msdn.microsoft.com/library/de...iltertopic.asp

While I would build that expression with a stringbuilder

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

"Frank" <noreply@nospam> schreef in bericht
news:pa********************************@4ax.com.. .
Hello All,

I am working on a vb.net app where I need to compare to 2 datatables
and determine if a string exists in one or both. The first dt is
filled from the db. A form is loaded and the appropriate items in a
checkedlist box are selected based on the dt. So far, no problem. Then
user can then edit the values in the checkedlist box and choose to
save changes. When they save changes, I throw the new values of the
checked items from the checklistbox into a new dt and compare the two.
Posed a similar question a couple of weeks ago, and was going to try a
comparison based on a datarow but was stymied because the 2 dt's don't
match. Any help will be greatly apprecitated!
Here is some code:

For i = 0 To myDSOrig.Tables(0).Rows.Count - 1
For z = 0 To dsChanged.Tables(0).Rows.Count - 1
If myDSOrig.Tables(0).Rows(i).Item(5).ToString =
dsChanged.Tables(0).Rows(z).Item(5).ToString Then
Exit For
Else
lblChg = New Label
lblChg.Text = myDSOrig.Tables(0).Rows(i)(5)
...
End If
Next z
Next i

This little routine works fine if more than 1 string does not match.
However, if only 1 string doesn't match, then it fails by capturing
the unequal string twice and one string that does match! ie:

TIA,
Dan


Feb 1 '06 #3
Frank,

No just one, if I understood your problem well, have you created a datatable
from your selecteditems in your checkedlistbox.

What you can try to do as well using this checkedlistbox direct or that
datatable can be

\\\
dim dv as new dataview(datatable1)
dim selectstring as new io.stringbuilder
For i as integer = 0 to checkedlistbox1.SelectedItems.count - 1 (or your
datatable)
dim item as string = checkedlistbox1.selectedItems(i).ToString (or
your datatable item)
'if the one above does not go, than reply
selectstring.add("YourColumname6 = ")
selectstring.add(item)
if i <> checkedlistbox1.selecteditems.count
selectstring.add(" Or ")
end if
Next
dim dv.datarowfilter = selectstring.ToString
///
Than should your dv gives the rows which are equal.

See this code as a kind of pseudo I have typed in this message and use as
you normally of course forever the intelisence.

Cor

"Frank" <noreply@nospam> schreef in bericht
news:ka********************************@4ax.com...

Cor,

Thanks for the response. As a daily lurker here, I can appreciate all
the help you dole out.

Just to make certain I understand your response: I could (should)
create two dataviews and then compare them to see if they are equal?

Also, I am not sure what Find method you are referring to.

In the meantime, I will do some research on the datatable.Select for
more info.

Thanks again!!!

Dan

On Tue, 31 Jan 2006 20:16:32 +0100, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:
Frank,

Was it you wich I asked why you did not use a Find (there are two and you
can use both for this).

Although a simple dataview with a datarowfilter containing a builded
string
with Or will probably as well do the job.

And than you have the possibility with the datatable.select.

I think that I in this case would go for the dataview with a rowfilter.

http://msdn.microsoft.com/library/de...iltertopic.asp

While I would build that expression with a stringbuilder

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

"Frank" <noreply@nospam> schreef in bericht
news:pa********************************@4ax.com. ..
Hello All,

I am working on a vb.net app where I need to compare to 2 datatables
and determine if a string exists in one or both. The first dt is
filled from the db. A form is loaded and the appropriate items in a
checkedlist box are selected based on the dt. So far, no problem. Then
user can then edit the values in the checkedlist box and choose to
save changes. When they save changes, I throw the new values of the
checked items from the checklistbox into a new dt and compare the two.
Posed a similar question a couple of weeks ago, and was going to try a
comparison based on a datarow but was stymied because the 2 dt's don't
match. Any help will be greatly apprecitated!
Here is some code:

For i = 0 To myDSOrig.Tables(0).Rows.Count - 1
For z = 0 To dsChanged.Tables(0).Rows.Count - 1
If myDSOrig.Tables(0).Rows(i).Item(5).ToString =
dsChanged.Tables(0).Rows(z).Item(5).ToString Then
Exit For
Else
lblChg = New Label
lblChg.Text = myDSOrig.Tables(0).Rows(i)(5)
...
End If
Next z
Next i

This little routine works fine if more than 1 string does not match.
However, if only 1 string doesn't match, then it fails by capturing
the unequal string twice and one string that does match! ie:

TIA,
Dan

Feb 1 '06 #4
Cor,

Thanks again for the assistance. It is greatly appreciated.
I have actually created 2 datatables, although now I think my logic
may be flawed.

In my app, the user can fill out a form (actually contains multiple
chkdlistbxs) and save their responses to the db. Later, the user can
bring the form back up, edit their responses, and re-save the form to
the db. With this in mind, I decided to do this when the user opens
the form to edit:
1. Pull the info from the db, throw it into a dataset, and iterate
thru that to check the appropriate checks.
2. Let the user check, un-check, whatever on the form.
3. When the save changes btn is clicked, I then iterate thru the
controls and throw the selected items into another dataset.

From this point, I need to determine exactly what was changed
(mythought was to compare the 2 datatables to see what differed) in
their edit, while retaining the old values. These old values must be
marked as "Changed", and the new values inserted into the db.

If this is how you understood the problem, I will give the dataview
and stringbuilder a go.

Thanks much again for the help!!!!!

Daniel
On Wed, 1 Feb 2006 07:59:06 +0100, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:
Frank,

No just one, if I understood your problem well, have you created a datatable
from your selecteditems in your checkedlistbox.

What you can try to do as well using this checkedlistbox direct or that
datatable can be

\\\
dim dv as new dataview(datatable1)
dim selectstring as new io.stringbuilder
For i as integer = 0 to checkedlistbox1.SelectedItems.count - 1 (or your
datatable)
dim item as string = checkedlistbox1.selectedItems(i).ToString (or
your datatable item)
'if the one above does not go, than reply
selectstring.add("YourColumname6 = ")
selectstring.add(item)
if i <> checkedlistbox1.selecteditems.count
selectstring.add(" Or ")
end if
Next
dim dv.datarowfilter = selectstring.ToString
///
Than should your dv gives the rows which are equal.

See this code as a kind of pseudo I have typed in this message and use as
you normally of course forever the intelisence.

Cor

"Frank" <noreply@nospam> schreef in bericht
news:ka********************************@4ax.com.. .

Cor,

Thanks for the response. As a daily lurker here, I can appreciate all
the help you dole out.

Just to make certain I understand your response: I could (should)
create two dataviews and then compare them to see if they are equal?

Also, I am not sure what Find method you are referring to.

In the meantime, I will do some research on the datatable.Select for
more info.

Thanks again!!!

Dan

On Tue, 31 Jan 2006 20:16:32 +0100, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:
Frank,

Was it you wich I asked why you did not use a Find (there are two and you
can use both for this).

Although a simple dataview with a datarowfilter containing a builded
string
with Or will probably as well do the job.

And than you have the possibility with the datatable.select.

I think that I in this case would go for the dataview with a rowfilter.

http://msdn.microsoft.com/library/de...iltertopic.asp

While I would build that expression with a stringbuilder

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

"Frank" <noreply@nospam> schreef in bericht
news:pa********************************@4ax.com ...
Hello All,

I am working on a vb.net app where I need to compare to 2 datatables
and determine if a string exists in one or both. The first dt is
filled from the db. A form is loaded and the appropriate items in a
checkedlist box are selected based on the dt. So far, no problem. Then
user can then edit the values in the checkedlist box and choose to
save changes. When they save changes, I throw the new values of the
checked items from the checklistbox into a new dt and compare the two.
Posed a similar question a couple of weeks ago, and was going to try a
comparison based on a datarow but was stymied because the 2 dt's don't
match. Any help will be greatly apprecitated!
Here is some code:

For i = 0 To myDSOrig.Tables(0).Rows.Count - 1
For z = 0 To dsChanged.Tables(0).Rows.Count - 1
If myDSOrig.Tables(0).Rows(i).Item(5).ToString =
dsChanged.Tables(0).Rows(z).Item(5).ToString Then
Exit For
Else
lblChg = New Label
lblChg.Text = myDSOrig.Tables(0).Rows(i)(5)
...
End If
Next z
Next i

This little routine works fine if more than 1 string does not match.
However, if only 1 string doesn't match, then it fails by capturing
the unequal string twice and one string that does match! ie:

TIA,
Dan


Feb 1 '06 #5
Cor,

Just wanted to tell you Thanks!!
Worked out the problem by using the dv.find method. Worked like a
charm. Problem Solved.

Sincerely,

Daniel

On Wed, 01 Feb 2006 08:39:30 -0600, Frank <noreply@nospam> wrote:
Cor,

Thanks again for the assistance. It is greatly appreciated.
I have actually created 2 datatables, although now I think my logic
may be flawed.

In my app, the user can fill out a form (actually contains multiple
chkdlistbxs) and save their responses to the db. Later, the user can
bring the form back up, edit their responses, and re-save the form to
the db. With this in mind, I decided to do this when the user opens
the form to edit:
1. Pull the info from the db, throw it into a dataset, and iterate
thru that to check the appropriate checks.
2. Let the user check, un-check, whatever on the form.
3. When the save changes btn is clicked, I then iterate thru the
controls and throw the selected items into another dataset.

From this point, I need to determine exactly what was changed
(mythought was to compare the 2 datatables to see what differed) in
their edit, while retaining the old values. These old values must be
marked as "Changed", and the new values inserted into the db.

If this is how you understood the problem, I will give the dataview
and stringbuilder a go.

Thanks much again for the help!!!!!

Daniel
On Wed, 1 Feb 2006 07:59:06 +0100, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:
Frank,

No just one, if I understood your problem well, have you created a datatable
from your selecteditems in your checkedlistbox.

What you can try to do as well using this checkedlistbox direct or that
datatable can be

\\\
dim dv as new dataview(datatable1)
dim selectstring as new io.stringbuilder
For i as integer = 0 to checkedlistbox1.SelectedItems.count - 1 (or your
datatable)
dim item as string = checkedlistbox1.selectedItems(i).ToString (or
your datatable item)
'if the one above does not go, than reply
selectstring.add("YourColumname6 = ")
selectstring.add(item)
if i <> checkedlistbox1.selecteditems.count
selectstring.add(" Or ")
end if
Next
dim dv.datarowfilter = selectstring.ToString
///
Than should your dv gives the rows which are equal.

See this code as a kind of pseudo I have typed in this message and use as
you normally of course forever the intelisence.

Cor

"Frank" <noreply@nospam> schreef in bericht
news:ka********************************@4ax.com. ..

Cor,

Thanks for the response. As a daily lurker here, I can appreciate all
the help you dole out.

Just to make certain I understand your response: I could (should)
create two dataviews and then compare them to see if they are equal?

Also, I am not sure what Find method you are referring to.

In the meantime, I will do some research on the datatable.Select for
more info.

Thanks again!!!

Dan

On Tue, 31 Jan 2006 20:16:32 +0100, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:

Frank,

Was it you wich I asked why you did not use a Find (there are two and you
can use both for this).

Although a simple dataview with a datarowfilter containing a builded
string
with Or will probably as well do the job.

And than you have the possibility with the datatable.select.

I think that I in this case would go for the dataview with a rowfilter.

http://msdn.microsoft.com/library/de...iltertopic.asp

While I would build that expression with a stringbuilder

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

"Frank" <noreply@nospam> schreef in bericht
news:pa********************************@4ax.co m...
> Hello All,
>
> I am working on a vb.net app where I need to compare to 2 datatables
> and determine if a string exists in one or both. The first dt is
> filled from the db. A form is loaded and the appropriate items in a
> checkedlist box are selected based on the dt. So far, no problem. Then
> user can then edit the values in the checkedlist box and choose to
> save changes. When they save changes, I throw the new values of the
> checked items from the checklistbox into a new dt and compare the two.
> Posed a similar question a couple of weeks ago, and was going to try a
> comparison based on a datarow but was stymied because the 2 dt's don't
> match. Any help will be greatly apprecitated!
> Here is some code:
>
> For i = 0 To myDSOrig.Tables(0).Rows.Count - 1
> For z = 0 To dsChanged.Tables(0).Rows.Count - 1
> If myDSOrig.Tables(0).Rows(i).Item(5).ToString =
> dsChanged.Tables(0).Rows(z).Item(5).ToString Then
> Exit For
> Else
> lblChg = New Label
> lblChg.Text = myDSOrig.Tables(0).Rows(i)(5)
> ...
> End If
> Next z
> Next i
>
> This little routine works fine if more than 1 string does not match.
> However, if only 1 string doesn't match, then it fails by capturing
> the unequal string twice and one string that does match! ie:
>
> TIA,
>
>
> Dan


Feb 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jade | last post by:
Hi, I just wanted to ask a quick question regarding datasets. I am creating 3 tables using a dataadapter. what i want to know is that is the relationship created between these datatables...
2
by: Z D | last post by:
Hello, I'm currently using Remoting (HTTP/Binary) to remote a simple object. Everything is working fine except for one function that returns an arraylist of datatables. When I call this...
3
by: Simple Simon | last post by:
Hi, I'm filling DataTable1 with the filenames from within a directory, and filling another DataTable2 with filenames from a SQL Db table. I'd like to compare the two, and delete the files from...
19
by: Will Lastname | last post by:
In one of the applications that I'm working on I have 2 sets of functions that build different datasets. Imagine 4 columns in a datagrid. Inside those 4 columns I have nested datalists. Two of...
4
by: sal | last post by:
Greets, All Converting array formula to work with datatables/dataset tia sal I finally completed a formula I was working on, see working code below. I would like to change this code so it...
4
by: Frank | last post by:
Hello, Developing an app where the user fills out a sometimes quite lengthy form of chkboxes, txtboxes, radbtns, etc. User responses are saved to a mySql db, which the user can later edit. When...
3
by: cj | last post by:
I've used datatables and datasets before. Datasets being able to hold more than one table and datatables being only one table. My mind keeps coming up with recordsets. I can't remember how they...
0
by: StefanPienaar | last post by:
Hi Guys Is there any way in c# (or vb.net) to extract a datatable of data from a dataset with multiple datatables which has relationships set up (containing combined data from the datatables)? ...
3
by: AllBeagle | last post by:
Hey Everyone, I'm having an issue that I hope someone can help me out with. If I have 2 DataTables (one that reads data from a DB and one that reads from a XML file), is there a way to combine...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.