Hey guys
I want to use a Datareader to populate all my combos and lists.
I am new to VB.net and come from VB6 dev background.
I cant get this to work.
Keep getting errors when trying to fill the DataTable with data.
Here is the Sub:
=======
Public Sub GetListDR(ByVal sSQL As String, ByVal dtData As DataTable)
Dim cmdData As New SqlClient.SqlCommand
Dim daData As New System.Data.SqlClient.SqlDataAdapter
Try
cCNN = CNN
cCNN.Open()
cmdData.CommandText = sSQL
cmdData.Connection = cCNN
daData.SelectCommand = cmdData
daData.SelectCommand.ExecuteReader() Here I get the error...
daData.Fill(dtData)
cCNN.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error getting Data", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
cmdData.Dispose()
daData.Dispose()
cCNN.Dispose()
End Try
=================
The error message I get says:
"There is already an Open Datareader associated with this Connection and it must be closed first."
This makes no sense to me. Am I even on the right track?
Someone got any ideas?
Rgds
Len
I want to use a Datareader to populate all my combos and lists.
I am new to VB.net and come from VB6 dev background.
I cant get this to work.
Keep getting errors when trying to fill the DataTable with data.
Here is the Sub:
=======
Public Sub GetListDR(ByVal sSQL As String, ByVal dtData As DataTable)
Dim cmdData As New SqlClient.SqlCommand
Dim daData As New System.Data.SqlClient.SqlDataAdapter
Try
cCNN = CNN
cCNN.Open()
cmdData.CommandText = sSQL
cmdData.Connection = cCNN
daData.SelectCommand = cmdData
daData.SelectCommand.ExecuteReader() Here I get the error...
daData.Fill(dtData)
cCNN.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error getting Data", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
cmdData.Dispose()
daData.Dispose()
cCNN.Dispose()
End Try
=================
The error message I get says:
"There is already an Open Datareader associated with this Connection and it must be closed first."
This makes no sense to me. Am I even on the right track?
Someone got any ideas?
Rgds
Len