Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Comparing Two DataSets

Reply
Thread Tools

Comparing Two DataSets

 
 
Will Lastname
Guest
Posts: n/a
 
      09-14-2005
I read some related articles very thoroughly and have at least a
general understanding of how to create the datatable. I have about 8
functions that are tied to my datalists that retrieve data. Each
function has different SQL statements that retrieve specific pieces of
data. What would be the best way of "concatenating" onto my current
datatable? If I dim a new datatable in each function won't the
information keep getting rewritten? I haven't found any literature
online in regards to this matter. Everything I've come across
presupposes that there is one subroutine with 2 or more datasets.

 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      09-15-2005
You can add as many datatables to a dataset as you'd like to. You just have
to make certain that each datatable has a different name.



For example (Assuming you already have a dataset that contains one or more
datatables) you may add another like so:



Public Function AddTableToDataSet(ByVal dataSetToAddTo As DataSet, ByVal
sqlCommand As SqlCommand, ByVal dataSetTableName As String) As DataSet

Try

Dim FortunateDataAdapter As SqlDataAdapter =
GetDataAdapter(sqlCommand)

FortunateDataAdapter.Fill(dataSetToAddTo, dataSetTableName)



Return dataSetToAddTo

Catch e As Exception

Throw e

End Try

End Function



Sincerely,

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Will Lastname" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I read some related articles very thoroughly and have at least a
> general understanding of how to create the datatable. I have about 8
> functions that are tied to my datalists that retrieve data. Each
> function has different SQL statements that retrieve specific pieces of
> data. What would be the best way of "concatenating" onto my current
> datatable? If I dim a new datatable in each function won't the
> information keep getting rewritten? I haven't found any literature
> online in regards to this matter. Everything I've come across
> presupposes that there is one subroutine with 2 or more datasets.
>



 
Reply With Quote
 
 
 
 
Will Lastname
Guest
Posts: n/a
 
      09-15-2005
So to test this I created a dataset with 2 tables. Let's just say
Table1 and Table2. In going through my FOR Next Loop I tried the
following:

For i = 0 To dsRowCount - 1
If ds.Tables("Table1").Rows(i)("ColumnName") <>
ds.Tables("Table2").Rows(i)("ColumnName") Then
response.write("not the same")
Else
resposne.write("ok")
End If
Next i

I am getting an "Object reference not set to an instance of an object."
error when I attempt this. Any suggestions or pointers?

 
Reply With Quote
 
Will Lastname
Guest
Posts: n/a
 
      09-15-2005
I filled one of the datasets in Function A and the other in Function B
and returned them. Am I not able to access them this way?

 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      09-15-2005
Will,

Running in debug mode, does your for next loop error out right away, or make
it through at least one iteration first?

I'm wondering if your tables have the same number of columns in them. If
they don't...

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Will Lastname" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> So to test this I created a dataset with 2 tables. Let's just say
> Table1 and Table2. In going through my FOR Next Loop I tried the
> following:
>
> For i = 0 To dsRowCount - 1
> If ds.Tables("Table1").Rows(i)("ColumnName") <>
> ds.Tables("Table2").Rows(i)("ColumnName") Then
> response.write("not the same")
> Else
> resposne.write("ok")
> End If
> Next i
>
> I am getting an "Object reference not set to an instance of an object."
> error when I attempt this. Any suggestions or pointers?
>



 
Reply With Quote
 
Will Lastname
Guest
Posts: n/a
 
      09-15-2005
It errors even if I try:

response.write(ds.Tables("Table").Rows(0)("ColumnN ame"))

I'm getting so frustrated with this.

Thanks for helping out!

 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      09-15-2005
Well, then it's not finding any columns at all for that table.

Try this code (it uses index numbers for the table, rows, columns so that if
the problem is the wrong table name you'll know):

'---Start by making certain that the dataset actually contains at least the
one table.
If ds.Tables(0) Is Nothing Then
Response.Write("Table Not Found!" & "<br>")
Else
'---Check if any rows exist
If ds.Tables(0).Rows.Count > 0 Then
Response.Write(ds.Tables(0).Rows.Count.ToString & "<br>")
Response.Write(ds.Tables(0).Rows(0).Columns(0).Col umnName)
Else
Response.Write("No Rows Found!")
End If
End If

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Will Lastname" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> It errors even if I try:
>
> response.write(ds.Tables("Table").Rows(0)("ColumnN ame"))
>
> I'm getting so frustrated with this.
>
> Thanks for helping out!
>



 
Reply With Quote
 
Will Lastname
Guest
Posts: n/a
 
      09-15-2005
This writes the name of the column name in the function where I fill
the dataset. If I try to compare a dataset in another function to this
dataset then I get an error.

 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      09-16-2005
Will,

I didn't realize you were declaring the dataset object inside of one
function and then using it again in another...

Objects declared within a function are only available within that function.

Instead declare your dataset object as a dataset outside of the first
function near the top of the page but inside of the class.

Private ds As DataSet

Then fill the dataset inside of your first function.

Private Function Number1()
'---Fill ds here
End Function

You won't have to declare ds inside of the function it's available
throughout the whole class.

Now it won't be nothing in the second function.


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Will Lastname" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> This writes the name of the column name in the function where I fill
> the dataset. If I try to compare a dataset in another function to this
> dataset then I get an error.
>



 
Reply With Quote
 
Will Lastname
Guest
Posts: n/a
 
      09-19-2005
Object reference not set to an instance of an object

Still getting this. I'm going to have to bag this idea for now.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do Datasets manage to get deserialized as DataSets instead of a wsdl.exe-created proxy class? Francisco Garcia ASP .Net Web Services 3 04-13-2006 05:53 PM
How do Datasets manage to get deserialized as DataSets instead of a wsdl.exe-created proxy class? Francisco Garcia ASP .Net 2 04-13-2006 10:41 AM
How do Datasets manage to get deserialized as DataSets instead of a wsdl.exe-created proxy class? news.microsoft.com ASP .Net Web Services 0 04-12-2006 09:07 AM
How do Datasets manage to get deserialized as DataSets instead of a wsdl.exe-created proxy class? news.microsoft.com ASP .Net 0 04-12-2006 09:07 AM
Efficiently comparing 2 datasets from different datasources Elliot M. Rodriguez ASP .Net 0 07-06-2004 02:38 PM



Advertisments