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

How to read a DataSet?

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
1 1832
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Marty | last post by:
Hi, Ok I use the OLEDBConnector and dataset to retrieve data from my Access DB. I have a problem to read/parse the dataset and I would like to know if I am using the right object to reach my...
1
by: Sal | last post by:
Hello all, I am working on a project with the following characteristics: 1. Load data from a SQL server table to an xml file 2. Read the xml file into a dataset. 3. Load data from the...
0
by: Peter | last post by:
I am having a problem reading an Excel file that is XML based. The directory I am reading contains Excel files that can be of two types. Either generic Microsoft based or XML based. I am reading...
15
by: ruca | last post by:
Hi, Can I read a .TXT File to a DataSet? How can I do that? I want to read his lines to a DropDownList. This lines are the names of employees that I export from an application that I have. I...
5
by: Guadala Harry | last post by:
This has to be easy... I have a DataSet stored in the Session object. I simply need to read it later and get the following error: Cannot implicitly convert type 'object' to 'System.Data.DataSet'...
3
by: Programmer | last post by:
Hi all I wan't to know if i'm able to read mail from a mail server. My mail server is a pop3 server (UNIX) and i want to be able to get the mails from an aspx or an asmx. with out using external...
16
by: Adda | last post by:
If I cycle through the MdiChildActivate event of the parent form I can read text in a textbox on the child mdiform -- console.writeline(Me.ActiveMdiChild.Controls(1).Text) But if I have a sub...
0
by: Hetal | last post by:
Hi there.. I am a VB6 developer so kinda trying to figure how to work with VB.NET. I have a scenario where i have a DataSet bound to a combo box, and i would like to read a row from the DataSet...
0
by: tom | last post by:
When I try to read in a csv file it gives me this error message. 'Cannot update. Database or object is read-only.' If I change the extension to txt it processes just fine. I have googled all...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.