Results 1 to 3 of 3

Thread: ODBC Connection

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    ODBC Connection

    I'm using an ODBC connection to connect to a SyBase Table. I connect to the DB ok, but It wont let me run a query. I get this error message on the line: objDR = cmd.ExecuteReader

    Value of type 'Microsoft.Data.Odbc.OdbcDataReader' cannot be converted to 'System.Data.OleDb.OleDbDataReader'.
    VB Code:
    1. Dim cn As OdbcConnection
    2.         cn = New OdbcConnection("DSN=SBPROD;Server=SYBASE;DB=fmsprod;Password=test;User ID=test")
    3.         Dim cmd As New OdbcCommand(sqlcmd)
    4.         Try
    5.             cn.Open()
    6.             objDR = cmd.ExecuteReader
    7.             If objDR.Read = True Then
    8.                 gerror_flag = True
    9.             Else
    10.                 gerror_flag = False
    11.             End If
    12.             cn.Close()
    13.         Catch ex As Exception
    14.             MsgBox(Err.Description)
    15.         End Try

    All I'm trying to do is see if any records are being retured...just a EOF test.

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Use Count(*)

    VB Code:
    1. Dim cn As OdbcConnection
    2. cn = New OdbcConnection("DSN=SBPROD;Server=SYBASE;DB=fmsprod;Password=test;User ID=test")
    3.  
    4. Dim cmd As OleDbCommand = New OleDbCommand("SELECT Count(*) FROM mytable WHERE  ...........", cn)
    5. Dim myCount As Integer = CInt(cmd.ExecuteScalar())
    6.  
    7. gerror_flag = myCount > 0

  3. #3
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    and make sure you pass the connection to the command, only now I noticed that you don't...

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