Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataReader for Combo boxes and Lists

Status
Not open for further replies.

Lenvdb

Programmer
Jun 21, 2002
81
GB
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top