Results 1 to 4 of 4

Thread: Error using SQLDataReader

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2004
    Posts
    54

    Error using SQLDataReader

    I'm getting the following error at the ' reader = cmd.ExecuteReader() ' line of the code below:

    An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

    Additional information: System error.


    Here's the code:

    VB Code:
    1. Dim oSQLConn As SqlConnection
    2.         Dim sql As String
    3.         Dim cmd As SqlCommand
    4.         Dim reader As SqlDataReader
    5.  
    6.         sql = "select column_name from information_schema.columns where table_name='selfserve_receipt_item_maillist"
    7.  
    8.         oSQLConn = New SqlConnection("Data Source=RMSDEVSQL1;Initial Catalog= SelfserveDB;user id=kiwisql;Password=fruitcake")
    9.         cmd = New SqlCommand(sql, oSQLConn)
    10.         oSQLConn.Open()
    11.         reader = cmd.ExecuteReader()


    I'm somewhat new to ADO.NET (what the heck happen to recordsets!) so I'm not used to working with SQLDataReader. Any help would be appreciated.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Error using SQLDataReader

    Do this:

    VB Code:
    1. Try
    2.     reader = cmd.ExecuteReader()  
    3. Catch sqlEx as SQLException
    4.   MessageBox.Show sqlEx.ToString
    5. End

    The message box will give you the exact error as reported by the connection. Post what it says and someone should be able to give you a better idea how to fix it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Error using SQLDataReader

    Without knowing the info Technome spoke of, I would venture a guess that in your sql string you have a single quote on one side of the table name, and not the other.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2004
    Posts
    54

    Re: Error using SQLDataReader

    Yep. That was it. Nothing wrong with the code aside from that. I'm just not thinking today! Thanks.

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