|
-
May 29th, 2013, 11:34 AM
#1
Thread Starter
Fanatic Member
Using a DataReader to populate a dataset
I'm having a bit of an issue with the following code. Basically, I have an oracle command that queries a database and returns records - that part works and is located above the snippet I've posted.
It loads the records into a datareader, and I can loop through the datareader - that works also.
Where I'm having a problem is - I want to loop through the datareader and load records into a datatable I've created (by dragging a Datatable object onto my form). I've then linked a datagridview on my form to that datatable.
The code below runs without error, but the datagridview doesn't populate with anything - wondering why?
The highlighted line below shows where I'm trying to see if there are any rows in my datatable. This always seems to be zero so the issue is somewhere in here I suspect.
Code:
Dim OracleCommand As New OracleCommand
OracleCommand.Connection = con
OracleCommand.CommandText = IP_SQL
OracleCommand.CommandType = CommandType.Text
Dim DataReader As OracleDataReader = OracleCommand.ExecuteReader()
If DataReader.HasRows Then
Do While DataReader.Read()
Dim anyRow As DataRow = dtNRCWorking.NewRow
anyRow("MRN") = Mid((DataReader.Item("CR_Number")), 3, 7)
Dim intwow As Integer = dtNRCWorking.Rows.Count
Loop
End If
DataGridView1.DataSource = dsNRCPicker
DataGridView1.DataMember = "dtNRCWorking"
DataGridView1.Refresh()
DataReader.Close()
Now I'm sure some of you are wondering why I'm doing this in the first place. Well - in short, I need to query data, massage it, and create a tab delimited file with it.
The DataReader let's me query, the dataset lets me loop through and massage the records/fields that I need to massage, and the datagridview is just for testing purposes so I can have a quick look at the data I'm building.
Last edited by The_Grudge; May 29th, 2013 at 11:42 AM.
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
|