473,403 Members | 2,222 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,403 software developers and data experts.

Help with DataSet return values

Rob
Hi,
I've been going at this for a few days and can't see the problem. Does
anyone see a problem with this code?
I have a call to a function that returns a dataset and when I assign
values to session variables, the values are the actual column names and
not the database value. I've tried using ordinal values and get the same
results.

--here's the code

--sql is defined here

Dim ds = New DataSet

ds = tools.GetDataSet(sql)

If ds.Tables(0).Columns("contact_id").ToString <> "" Then
Session("ContactID") = ds.Tables(0).Columns("contact_id").ToString
Session("CompanyID") = ds.Tables(0).Columns("company_id").ToString
GetContactData(Session("ContactID"), Session("CompanyID"))
ShowPanel(pnlStep1)
Else
lblMessage.Text = "User information not found"
End If

--My function looks like this

Public Shared Function GetDataSet(ByVal SQL As String) As DataSet
Dim cn As String
Dim adapter As SqlDataAdapter
Dim connection As SqlConnection

cn = ConfigurationSettings.AppSettings("CONN_STRING")

Try
connection = New SqlConnection(cn)
connection.Open()

adapter = New SqlDataAdapter(SQL, connection)
Dim myData As New DataSet

adapter.Fill(myData)
Return myData
Catch ex As Exception
Throw New Exception(ex.Message)
Finally
'clean up
adapter.Dispose()
connection.Close()
End Try

End Function

when I refer to ds.tables(0).Columns("contact_id").tostring or
ds.tables(0).columns(9).toString()...the value returned is "contact_id"
rather than 936. I've used this function before and it works fine. Does
anyone see a problem?

Thanks
Rob


*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #1
4 3825
I dont' use the sntax you do but with a datatable off the rows propety
is an item property with i use as in:
Dt.Rows(0).Item("FinalACV").ToString

Hope this helps

Nov 19 '05 #2
you are ToStringing a DataColumn value.... you aren't even specifying a row!

ds.Tables(0).Rows(0)("contact_id")
ds.Tables(0).Rows(10000)("contact_id")

Also

(a) why dim ds = new DataSet ? your GetDataSet is creating a new dataset
(b) turn option strict on it'll save you some headaches
(c) don't needlessly catch exceptions ala:
Catch ex As Exception
Throw New Exception(ex.Message)
that's just repackaging the exception with no added benefit. just remove
the catch and keep your try/finally

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Rob" <ro****@hotmail.com> wrote in message
news:OX**************@TK2MSFTNGP12.phx.gbl...
Hi,
I've been going at this for a few days and can't see the problem. Does
anyone see a problem with this code?
I have a call to a function that returns a dataset and when I assign
values to session variables, the values are the actual column names and
not the database value. I've tried using ordinal values and get the same
results.

--here's the code

--sql is defined here

Dim ds = New DataSet

ds = tools.GetDataSet(sql)

If ds.Tables(0).Columns("contact_id").ToString <> "" Then
Session("ContactID") = ds.Tables(0).Columns("contact_id").ToString
Session("CompanyID") = ds.Tables(0).Columns("company_id").ToString
GetContactData(Session("ContactID"), Session("CompanyID"))
ShowPanel(pnlStep1)
Else
lblMessage.Text = "User information not found"
End If

--My function looks like this

Public Shared Function GetDataSet(ByVal SQL As String) As DataSet
Dim cn As String
Dim adapter As SqlDataAdapter
Dim connection As SqlConnection

cn = ConfigurationSettings.AppSettings("CONN_STRING")

Try
connection = New SqlConnection(cn)
connection.Open()

adapter = New SqlDataAdapter(SQL, connection)
Dim myData As New DataSet

adapter.Fill(myData)
Return myData
Catch ex As Exception
Throw New Exception(ex.Message)
Finally
'clean up
adapter.Dispose()
connection.Close()
End Try

End Function

when I refer to ds.tables(0).Columns("contact_id").tostring or
ds.tables(0).columns(9).toString()...the value returned is "contact_id"
rather than 936. I've used this function before and it works fine. Does
anyone see a problem?

Thanks
Rob


*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #3
Rob

Thanks for the advice Karl, I've turned option explicit on and fixed a
bunch of other errors as well. As far as declaring a dataset...shouldn't
I be declaring a dataset to accept the dataset that is being passed?
What would I use to reference it's contents if I don't. Also don't I
need a Catch...how can I evaluate the error from the calling function if
it doesn't throw back the error?

Thanks
Rob
*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #4
I take it the original error was fixed?

You need to declare your DataSet, but not instantiated it..
Dim ds = New DataSet
ds = tools.GetDataSet(sql)

should be

dim ds as DataSet
ds = Tools.GetdataSet(sql)

no need to create a "new" dataset, since GetDataSet is already doing that.
Apologies for not being clear.

Uncaught examples automatically bubble up. By doing:
Catch ex As Exception
Throw New Exception(ex.Message)

you aren't really adding any value. AS a matter of fact, you are making it
worse by emdedding the actual exception (the one with the useful error
information) inside a fictional one. If you don't "catch" it'll bubble up
the original exception - which is what you want.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Rob" <ro****@hotmail.com> wrote in message
news:uz*************@TK2MSFTNGP10.phx.gbl...

Thanks for the advice Karl, I've turned option explicit on and fixed a
bunch of other errors as well. As far as declaring a dataset...shouldn't
I be declaring a dataset to accept the dataset that is being passed?
What would I use to reference it's contents if I don't. Also don't I
need a Catch...how can I evaluate the error from the calling function if
it doesn't throw back the error?

Thanks
Rob
*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #5

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

Similar topics

3
by: William Buchanan | last post by:
Hi I have the following stored proc in interbase (which might contain errors - i'm doing it off the top of my head), which I would like to convert into oracle. Can you help? What I want back is...
5
by: DraguVaso | last post by:
Hi, Something I don't understand about a Typed DataSet: When a value in the DataSet is DBNull, it throws this error: "Cannot get value because it is DBNull". But aren't Typed DataSets...
2
by: Sumaira Ahmad | last post by:
Hi All My Web Service is returning a DataSet. I realized that we cannot return a DataReader.. Normally we can use a DataReader( when not using Web services) and access it as below to assign...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
0
by: r1 | last post by:
I am relatively inexperienced in using delegates and asynchronous methods. I read several articles, and then I developed my own code with a mission to improve the performance. Wow! I cannot...
3
by: aking | last post by:
Dear Python people, im a newbie to python and here...so hello! Im trying to iterate through values in a dictionary so i can find the closest value and then extract the key for that...
4
by: SteveT | last post by:
I am wanting to populate several treeviews, one for the <TRs> group and one for the <TGsgroup. Is there a simplier way to populate the Treeview than the one I did below? It seems difficult to...
6
by: nzkks | last post by:
Hi I am using these: ASP.Net 2.0 with VB.Net, Visual Studio 2005, SQL Server 2005 I suspect, there is something missing in BLL class. I created the ASP.Net form also and checked whether it is...
1
by: jrod11 | last post by:
Hi everyone, I am currently working on a project that pulls data from sql and displays it in an html file. This is working fine, but I am trying to make it a little more fancy using this cool source...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.