Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Something is Wrong with DataReader
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Something is Wrong with DataReader

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Something is Wrong with DataReader
    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 

 

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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()




Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.