|
-
May 2nd, 2013, 12:46 PM
#1
Thread Starter
Hyperactive Member
Looping through dataset
I need to take all the data in a dataset and, for each record, I need to find if there are other records that match it based on three fields and if there are, I need to mark the oldest one based on a date field. The only way I could think of to do this is to loop through the dataset and create a new select statement for each record and fill a new dataset with all the matches for that record, then process and repeat. Does that make sense? or is there a much easier way to do it? I have the following code so far, but I keep getting an error after the second fill method that says "object reference not set to instance of an object....". That makes no sense to me since I declare it with "new" above. I commented out the rest of the second select statement just to see if it was the search that was coming up with no data.
Code:
Dim dsENY As New DataSet
Dim dsFound As New DataSet
Dim daENY As New OleDb.OleDbDataAdapter
daENY.SelectCommand = New OleDb.OleDbCommand
daENY.UpdateCommand = New OleDb.OleDbCommand
With daENY.SelectCommand
.Connection = OleDbConnection1
.CommandText = "SELECT * FROM ENY1THRU4"
.CommandType = CommandType.Text
End With
With daENY.UpdateCommand
.Connection = OleDbConnection1
.CommandType = CommandType.Text
End With
dsENY.Clear()
Try
daENY.Fill(dsENY, "ENY1THRU4")
Catch ex As Exception
MessageBox.Show(ex.ToString, "ERROR LOADING DATA", MessageBoxButtons.OK)
End Try
Label1.Text = dsENY.Tables("ENY1THRU4").Rows.Count.ToString & " PNRs to move..."
ProgressBar1.Minimum = 1
ProgressBar1.Maximum = dsENY.Tables("ENY1THRU4").Rows.Count
Dim dr As DataRow
For Each dr In dsENY.Tables("ENY1THRU4").Rows
daENY.SelectCommand.CommandText = "SELECT * FROM ENY1THRU4" 'WHERE PNRNO = '" & dr("PNR") & "' AND HPROP_NO = '" & dr("HOD") & "'"
dsFound.Clear()
Try
daENY.Fill(dsFound, "ENY1TRHU4")
Catch ex As Exception
MessageBox.Show(ex.ToString, "ERROR FOUND", MessageBoxButtons.OK)
End Try
Label1.Text = dsFound.Tables("ENY1THRU4").Rows.Count.ToString & " PNRs to move..." 'THIS IS WHERE I GET THE INSTANCE ERROR
Application.DoEvents()
Next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|