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

How to read a DataSet?

P: n/a
How can I loop through the rows of a DataSet and send the "fields" to the
Function as I've attempted to do in my code? Error is at "While
dsLineItems.Read()" . I'm trying to construct a Sub which builds a DataSet
and loops through the records or "rows" of the DataSet and call a Function
for each row found. The Function will insert the data into another table.
(Essentially what I'm doing is pulling records from one Temp working table
and inserting them into another indentical table). About a week ago, I asked
about how to read data from one table and insert it into another. I was
considering a multi-dim array but someone suggested I just use a DataSet. It
seemed like a simpler approach so that's why I'm using a DS to store data
from one table to be inserted into another.

Thanks!

Sub ReadTempLineItems(intNewReqID As Integer)
Dim objConnection As SqlConnection
Dim adpData As SqlDataAdapter
Dim dsLineItems As DataSet

Dim strConnectString As String
Dim strSQL As String

strConnectString =
System.Configuration.ConfigurationSettings.AppSett ings("SqlConnection")
strSQL = "SELECT * FROM POItemsTemp WHERE PurchaseOrderID = " &
Session("intReqID")

dsLineItems = New DataSet()
objConnection = New SqlConnection(strConnectString)
adpData = New SqlDataAdapter(strSQL, objConnection)
adpData.Fill(dsLineItems, "LineItems")

While dsLineItems.Read() <---- Error
InsertLineItems(intNewReqID, dsLineItems("BudgetID"),
dsLineItems("AllocAmt"), dsLineItems("Description"),
dsLineItems("Quantity"), dsLineItems("UOM"), dsLineItems("UnitPrice"))
End While

drLineItems.Close()
objConnection.Close()

End Sub


Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Shane:

One thing to be careful about is that a DataSet doesn't contain rows but
contains a collection of DataTable objects and the DataTable objects contain
rows.

Something along the lines of:

Dim dsLineItems As DataSet = New DataSet()

' fill dsLineItems...

Dim row As DataRow
For Each row in dsLineItems.Tables(0).Rows
' do work, i.e. row("Quantity") = x * y
Next

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/
How can I loop through the rows of a DataSet and send the "fields" to
the Function as I've attempted to do in my code? Error is at "While
dsLineItems.Read()" . I'm trying to construct a Sub which builds a
DataSet and loops through the records or "rows" of the DataSet and
call a Function for each row found. The Function will insert the data
into another table. (Essentially what I'm doing is pulling records
from one Temp working table and inserting them into another indentical
table). About a week ago, I asked about how to read data from one
table and insert it into another. I was considering a multi-dim array
but someone suggested I just use a DataSet. It seemed like a simpler
approach so that's why I'm using a DS to store data from one table to
be inserted into another.

Thanks!

Sub ReadTempLineItems(intNewReqID As Integer)

Dim objConnection As SqlConnection
Dim adpData As SqlDataAdapter
Dim dsLineItems As DataSet
Dim strConnectString As String
Dim strSQL As String
strConnectString =
System.Configuration.ConfigurationSettings.AppSett ings("SqlConnection"
) strSQL = "SELECT * FROM POItemsTemp WHERE PurchaseOrderID = " &
Session("intReqID")

dsLineItems = New DataSet()
objConnection = New SqlConnection(strConnectString)
adpData = New SqlDataAdapter(strSQL, objConnection)
adpData.Fill(dsLineItems, "LineItems")
While dsLineItems.Read() <---- Error
InsertLineItems(intNewReqID, dsLineItems("BudgetID"),
dsLineItems("AllocAmt"), dsLineItems("Description"),
dsLineItems("Quantity"), dsLineItems("UOM"), dsLineItems("UnitPrice"))
End While

drLineItems.Close()
objConnection.Close()
End Sub

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.