Results 1 to 3 of 3

Thread: Dim rs As New OdbcDataReader() can't asign because private

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Dim rs As New OdbcDataReader() can't asign because private

    VB Code:
    1. Try
    2.             If Application("Connection") Is Nothing Then
    3.                 Dim mySQLConnStr As String = "Driver={MySQL};" & _
    4.                                             "Server=209.61.188.54;" & _
    5.                                             "Port=3306;" & _
    6.                                             "Option=131072;" & _
    7.                                             "Stmt=;" & _
    8.                                             "Database=wildhorse;" & _
    9.                                             "Uid=script;" & _
    10.                                             "Pwd=php_script;"
    11.  
    12.                 Dim cn As OdbcConnection = New OdbcConnection(mySQLConnStr)
    13.                 Application("Connection") = cn
    14.                 cn.Open()
    15.  
    16.                 Dim cmd As New OdbcCommand("SELECT * FROM tblSpecialEvents", cn)
    17.                 Dim ret As Object = cmd.ExecuteScalar()
    18.                 Dim rs As New OdbcDataReader()' error
    19.                 Response.Write(rs.GetValue(0))
    20.                 If Not IsDBNull(ret) Then Application("Visitors") = CInt(Val(ret))
    21.             End If
    22.         Catch ex As OdbcException
    23.             Application("Connection") = Nothing
    24.             Application("ConnectionError") = ex.Message
    25.         End Try

    This says i cant assign rs as new OdbcDatareader becasue its in a private sub...? I dont get it... Also is 'Dim rs As New OdbcDataReader()' that what i should use to get data from a recordset? Or is there something in the command object i should use? Argg i'm so confused..
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You cant instantiate a DataReader since the constructor is private. You have to let the Command Object return a DataReader.

    Try this:
    VB Code:
    1. Dim rs As OdbcDataReader = cmd.ExecuteReader()

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Also you wouldn't use ExecuteScalar like that. ExecuteScalar will return the value of the 1st column of the query that is being executed.

    VB Code:
    1. Dim ret As Integer= cmd.ExecuteScalar()
    2.                 Response.Write(ret)
    3.                 If Not IsDBNull(ret) Then Application("Visitors") = ret

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width