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