Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. I need help about "MyCommand.ExecuteReader()"

I need help about "MyCommand.ExecuteReader()"

Scheduled Pinned Locked Moved Visual Basic
help
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jlizardo
    wrote on last edited by
    #1

    :confused: Hi everyone i don't know what happend on this code. I every help page or site, them tell the same code, but in my machine is not working. Please help me on that. The msg error is " An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll " And the line error is " myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) " Please i need that as soon as possible. :confused: Thank Johnny Lizardo Johnny Lizardo

    D 1 Reply Last reply
    0
    • J jlizardo

      :confused: Hi everyone i don't know what happend on this code. I every help page or site, them tell the same code, but in my machine is not working. Please help me on that. The msg error is " An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll " And the line error is " myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) " Please i need that as soon as possible. :confused: Thank Johnny Lizardo Johnny Lizardo

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      We need to know a bit more, like what the rest of the myCommand object is setup with and what the connection object looks like. It would appear that the rest of the command object is not setup with a SELECT statement that is compatible with the ExecuteReader method. Also, how is myReader declared? RageInTheMachine9532

      J 1 Reply Last reply
      0
      • D Dave Kreskowiak

        We need to know a bit more, like what the rest of the myCommand object is setup with and what the connection object looks like. It would appear that the rest of the command object is not setup with a SELECT statement that is compatible with the ExecuteReader method. Also, how is myReader declared? RageInTheMachine9532

        J Offline
        J Offline
        jlizardo
        wrote on last edited by
        #3

        Imports System.Data.SqlClient Module SQL Public sqlSelect As String Public myConnection As New SqlConnection() Public myReader As SqlDataReader myConnection.ConnectionString = "data source=JLZONE\JLZONE;initial catalog=PMC;integrated _ security=SSPI;persist security info=False;workstation id=JLZONE;packet size=4096" myConnection.Open() sqlSelect = "Select * from Users" Dim myCommand As New SqlCommand(sqlSelect, myConnection) myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) While myReader.Read() Console.WriteLine("myreader record = " & " " & myReader.GetValue(1)) End While myReader.Close() myConnection.Close() myConnection.Dispose() End Function Johnny Lizardo

        D 1 Reply Last reply
        0
        • J jlizardo

          Imports System.Data.SqlClient Module SQL Public sqlSelect As String Public myConnection As New SqlConnection() Public myReader As SqlDataReader myConnection.ConnectionString = "data source=JLZONE\JLZONE;initial catalog=PMC;integrated _ security=SSPI;persist security info=False;workstation id=JLZONE;packet size=4096" myConnection.Open() sqlSelect = "Select * from Users" Dim myCommand As New SqlCommand(sqlSelect, myConnection) myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) While myReader.Read() Console.WriteLine("myreader record = " & " " & myReader.GetValue(1)) End While myReader.Close() myConnection.Close() myConnection.Dispose() End Function Johnny Lizardo

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          OK. Everything looks good with your code. Sooooo.... Two possibilities exist that can generate this problem: One is the connection string. Does the database exist? Does is require a username and password to be sent in the connection string? Does it have a real live table called 'Users' or is it a View? Does the Select statement really work? The second is a busted MDAC installation. You might want to try reinstalling MDAC 2.6 SP2 or better. You can pick that up here[^]. RageInTheMachine9532

          J 1 Reply Last reply
          0
          • D Dave Kreskowiak

            OK. Everything looks good with your code. Sooooo.... Two possibilities exist that can generate this problem: One is the connection string. Does the database exist? Does is require a username and password to be sent in the connection string? Does it have a real live table called 'Users' or is it a View? Does the Select statement really work? The second is a busted MDAC installation. You might want to try reinstalling MDAC 2.6 SP2 or better. You can pick that up here[^]. RageInTheMachine9532

            J Offline
            J Offline
            jlizardo
            wrote on last edited by
            #5

            Thannnnnkkkkkk men.. the MDAC installation was the problem... waooooooo.... that's great.. Johnny

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups