Print Page | Close Window

Something is Wrong with DataReader

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=12081
Printed Date: 29 March 2026 at 3:11am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Something is Wrong with DataReader
Posted By: Misty
Subject: Something is Wrong with DataReader
Date Posted: 08 October 2004 at 2:00pm

I am getting the following error message: Compiler Error Message: BC30311: Value of type 'System.Data.SqlClient.SqlDataReader' cannot be converted to 'System.Data.SqlClient.SqlDataAdapter'.

Source Error:

Line 32:    
Line 33:         'execute the SQL statement against the command to fill the DataReader 
Line 34:         dtrStates = objCommand.ExecuteReader() 

What am I doing wrong? I thought that the SQLDataAdapter was right.

Here's my code:

Sub BindDropDownList()

 

        Dim strConnect As String

        Dim strSQL as String

        Dim objConnect As New System.Data.SqlClient.SQLConnection(ConnectionString())

        Dim objCommand As New System.Data.SqlClient.SQLCommand

        Dim dtrStates As New SQLDataAdapter()

        Dim ddlStates as new DataSet()

 

            

        objConnect.Open()

 

        'Create SQL statement

        strSQL = "Select * from State Order By StateName"

 

        'Set the Command Object properties

        objCommand.Connection = objConnect

        objCommand.CommandText = strSQL

  

        'execute the SQL statement against the command to fill the DataReader

        dtrStates = objCommand.ExecuteReader()

 

        'Setup DropDown box

        ddlStates.DataSource = dtrStates

        ddlStates.DataValueField = "State"

        ddlStates.DataTextField = "StateName"

 

        'Bind the DropDownList control to the DataReader

        ddlStates.DataBind()

 

 

End Sub 

 




Replies:
Posted By: Mart
Date Posted: 08 October 2004 at 2:26pm
You can't do it like that, this should work:


        Dim strConnect As String

        Dim strSQL as String

        Dim dtrStates As SQLDataAdapter

        Dim dsStates as new DataSet


        strSQL = "Select * from State Order By StateName"

 
         dtrStates = New SqlDataAdapter(strSQL, strConnect)


 dtrStates.Fill(dsStates)


        'Setup DropDown box

        ddlStates.DataSource = dsStates

        ddlStates.DataValueField = "State"

        ddlStates.DataTextField = "StateName"

 

        'Bind the DropDownList control to the DataReader

        ddlStates.DataBind()






Posted By: Misty
Date Posted: 08 October 2004 at 3:19pm

Mart,

Thank you for the code! I thought I'd let you know that I had to do this: Dim strConnect As New System.Data.SqlClient.SQLConnection(ConnectionString())  ; instead of just Dim StrConnect As String to get this working. I didn't give you information on my connection details.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net