473,606 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Rea d()" . 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 ReadTempLineIte ms(intNewReqID As Integer)
Dim objConnection As SqlConnection
Dim adpData As SqlDataAdapter
Dim dsLineItems As DataSet

Dim strConnectStrin g As String
Dim strSQL As String

strConnectStrin g =
System.Configur ation.Configura tionSettings.Ap pSettings("SqlC onnection")
strSQL = "SELECT * FROM POItemsTemp WHERE PurchaseOrderID = " &
Session("intReq ID")

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

While dsLineItems.Rea d() <---- Error
InsertLineItems (intNewReqID, dsLineItems("Bu dgetID"),
dsLineItems("Al locAmt"), dsLineItems("De scription"),
dsLineItems("Qu antity"), dsLineItems("UO M"), dsLineItems("Un itPrice"))
End While

drLineItems.Clo se()
objConnection.C lose()

End Sub


Nov 19 '05 #1
1 1846
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.Tab les(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.Rea d()" . 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 ReadTempLineIte ms(intNewReqID As Integer)

Dim objConnection As SqlConnection
Dim adpData As SqlDataAdapter
Dim dsLineItems As DataSet
Dim strConnectStrin g As String
Dim strSQL As String
strConnectStrin g =
System.Configur ation.Configura tionSettings.Ap pSettings("SqlC onnection"
) strSQL = "SELECT * FROM POItemsTemp WHERE PurchaseOrderID = " &
Session("intReq ID")

dsLineItems = New DataSet()
objConnection = New SqlConnection(s trConnectString )
adpData = New SqlDataAdapter( strSQL, objConnection)
adpData.Fill(ds LineItems, "LineItems" )
While dsLineItems.Rea d() <---- Error
InsertLineItems (intNewReqID, dsLineItems("Bu dgetID"),
dsLineItems("Al locAmt"), dsLineItems("De scription"),
dsLineItems("Qu antity"), dsLineItems("UO M"), dsLineItems("Un itPrice"))
End While

drLineItems.Clo se()
objConnection.C lose()
End Sub

Nov 19 '05 #2

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

Similar topics

7
1799
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 goal. And I don't want to spend hours to find out, would you tell me if I'm going in the wrong path? Private dbConnector As New OleDbConnection
1
10248
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 dataset into another SQL server table. I was able to accomplish the first objective.
0
4685
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 the Microsoft based files with an OleDbDataAdapter. Then filling the contents of the first worksheet into a dataset. However when I try to add the XML based file to my dataset using an XmlTextReader I can never seem to get it to save to a...
15
4744
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 export them to a .txt file and I want to "work" with this employees in my aspx page. Can you help me? It's a little bit strange, but it's what I need. :)
5
7770
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' From a code-behind module of an ASPX page, how do I read the contents of a DataSet that is stored in the Session? Thanks in advance.
3
2299
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 objs. Only classes from the .NET Is there a way?? Thanks in advance
16
453
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 in the Parent form and reference a child mdi form like this: Sub ReadText()
0
1260
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 based on the item selected in the Combo Box. For e.g. I have a dataset that has 1 table containing 3 fields say ID, Name, and Address.
0
2267
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 sites on this and I haven't found anything to help. (tried registry stuff, reinstall .NET 2.0, patches). This just broke out the blue too which is weird because it was running fine on our server on monday but now it pukes. Here is the code. ...
0
8009
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7939
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8432
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
5962
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5456
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3919
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1548
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.