G
Guest
Hi,
I am trying to fill a read-only datatable with a datareader in ADO.NET 1.1.
I am filling an ArrayList with the datareader, but having a heck of a time
trying to figure out how to populate the datatable with my ArrayList.
Code so far:
Dim dbRecordsHolder As New ArrayList
Private WithEvents dt As New DataTable("dtDaysClaims")
Private Sub DayEndClaimReviewForm_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Me.cnSA.ConnectionString = strConn
Try
Me.sqlCmdGetDaysClaims.Parameters(1).Value = Today
Me.cnSA.Open()
Dim sqlDr As SqlDataReader =
Me.sqlCmdGetDaysClaims.ExecuteReader(CommandBehavior.CloseConnection)
If sqlDr.HasRows Then
For Each rec As IDataRecord In sqlDr
Me.dbRecordsHolder.Add(rec)
Next rec
End If
This successfully populates my ArrayList. I am then trying to use either
DataTable.BeginLoadData() and LoadDataRow(value() As Object, AcceptChanges As
Boolean), or the typical NewRow --> AddRow methods. To iterate through my
ArrayList, I have tried both .GetEnumerator and .MoveNext, as well as using
the ArrayList(index As Int32) with a For i as Int32 = 0 to
Me.dbRecordsHolder.Count - 1. Both methods return an Object, which I am
unsuccessfully trying to cast as either a DataRow or an Object(), to fit my
methods of populating the DataTable mentioned above. I know I could just use
a DataAdapter (in fact, I currently am doing just that). However, my app
populates SEVERAL of these lookup type, read-only DataTables, and I am
looking to be more efficient.
Thanks in advance for any advice.
I am trying to fill a read-only datatable with a datareader in ADO.NET 1.1.
I am filling an ArrayList with the datareader, but having a heck of a time
trying to figure out how to populate the datatable with my ArrayList.
Code so far:
Dim dbRecordsHolder As New ArrayList
Private WithEvents dt As New DataTable("dtDaysClaims")
Private Sub DayEndClaimReviewForm_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Me.cnSA.ConnectionString = strConn
Try
Me.sqlCmdGetDaysClaims.Parameters(1).Value = Today
Me.cnSA.Open()
Dim sqlDr As SqlDataReader =
Me.sqlCmdGetDaysClaims.ExecuteReader(CommandBehavior.CloseConnection)
If sqlDr.HasRows Then
For Each rec As IDataRecord In sqlDr
Me.dbRecordsHolder.Add(rec)
Next rec
End If
This successfully populates my ArrayList. I am then trying to use either
DataTable.BeginLoadData() and LoadDataRow(value() As Object, AcceptChanges As
Boolean), or the typical NewRow --> AddRow methods. To iterate through my
ArrayList, I have tried both .GetEnumerator and .MoveNext, as well as using
the ArrayList(index As Int32) with a For i as Int32 = 0 to
Me.dbRecordsHolder.Count - 1. Both methods return an Object, which I am
unsuccessfully trying to cast as either a DataRow or an Object(), to fit my
methods of populating the DataTable mentioned above. I know I could just use
a DataAdapter (in fact, I currently am doing just that). However, my app
populates SEVERAL of these lookup type, read-only DataTables, and I am
looking to be more efficient.
Thanks in advance for any advice.