Type mismatch with SqlDataReader


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Type mismatch with SqlDataReader

  1. #1
    Angela Guest

    Type mismatch with SqlDataReader


    Hi,
    I am getting a type mismatch error when I try to populate a SQLDataReader
    object. Here is the exact text of the error message:

    Value of type 'System.Data.SqlClient.SqlDataReader' cannot be converted to
    '1-dimensional array of System.Data.SqlClient.SqlDataReader'.

    I don't know what is wrong. As far as I can tell, ExecuteReader returns
    a SQLDataReader so the types should match.

    Here is my code:

    Dim strSQL As String
    strSQL = "Select * From Persons where LoginName = '" & mstrLoginName &
    _
    "' AND Password = '" & mstrPassword & "'"

    Dim objConn As New SqlConnection()
    objConn.ConnectionString = "user id=tracker;password=XXXXXXX;initial catalog=Tracker;data
    source=(local);Connect Timeout=30"

    Dim objCommand As New SqlCommand(strSQL, objConn)
    objConn.Open()

    Dim objDataReader As SqlDataReader()

    'ERROR ON THE FOLLOWING LINE
    objDataReader = objCommand.ExecuteReader()


    In case it makes a difference, I am using VS.NET RC0.

    Thx,
    Angela

  2. #2
    Russell Jones Guest

    Re: Type mismatch with SqlDataReader

    Remove the parentheses at the end of this line.

    Dim objDataReader As SqlDataReader()

    The parentheses create a one-dimensional array of SqlDataReader objects.

    Russell Jones
    Sr. Web Development Editor,
    DevX.com


    "Angela" <angelabinkowski@yahoo.com> wrote in message
    news:3bf9d013$1@147.208.176.211...
    >
    > Hi,
    > I am getting a type mismatch error when I try to populate a

    SQLDataReader
    > object. Here is the exact text of the error message:
    >
    > Value of type 'System.Data.SqlClient.SqlDataReader' cannot be converted to
    > '1-dimensional array of System.Data.SqlClient.SqlDataReader'.
    >
    > I don't know what is wrong. As far as I can tell, ExecuteReader returns
    > a SQLDataReader so the types should match.
    >
    > Here is my code:
    >
    > Dim strSQL As String
    > strSQL = "Select * From Persons where LoginName = '" & mstrLoginName &
    > _
    > "' AND Password = '" & mstrPassword & "'"
    >
    > Dim objConn As New SqlConnection()
    > objConn.ConnectionString = "user id=tracker;password=XXXXXXX;initial

    catalog=Tracker;data
    > source=(local);Connect Timeout=30"
    >
    > Dim objCommand As New SqlCommand(strSQL, objConn)
    > objConn.Open()
    >
    > Dim objDataReader As SqlDataReader()
    >
    > 'ERROR ON THE FOLLOWING LINE
    > objDataReader = objCommand.ExecuteReader()
    >
    >
    > In case it makes a difference, I am using VS.NET RC0.
    >
    > Thx,
    > Angela




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center