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. ADO.NET and VB

ADO.NET and VB

Scheduled Pinned Locked Moved Visual Basic
databasecsharpsaleshelptutorial
3 Posts 3 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.
  • I Offline
    I Offline
    Imtiaz Murtaza
    wrote on last edited by
    #1

    I fetch a record from databse using SQL query. The result is in my command object. But i don't know that how to retrieve the values from command objects and how to iterate through it. Can any one help me ?

    Dim rs As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand("select * from customer")
    SQLREADER = rs.ExecuteReader
    rs.ExecuteNonQuery()

    Imtiaz Imtiaz

    C D 2 Replies Last reply
    0
    • I Imtiaz Murtaza

      I fetch a record from databse using SQL query. The result is in my command object. But i don't know that how to retrieve the values from command objects and how to iterate through it. Can any one help me ?

      Dim rs As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand("select * from customer")
      SQLREADER = rs.ExecuteReader
      rs.ExecuteNonQuery()

      Imtiaz Imtiaz

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      From the code you have given the result will not be in the Command Object as there are no output parameters. Second, the rs.ExecuteNonQuery() won't do anything useful because your SQL is a SELECT statement. ExecuteNonQuery is for when you do not expect any results back. Your results are in the SqlDataReader object. Use the SqlDataReader.Read()[^] method to extract each record. The return value of this method will be true if a record was read, or false if there are no more records. The data reader holds tha values of the current record, it has a number of Get...[^] methods to assist you in getting the values for each of the fields. After you have the values you need for a record, loop around again calling the Read method until you have all your data. Does this help?


      "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

      1 Reply Last reply
      0
      • I Imtiaz Murtaza

        I fetch a record from databse using SQL query. The result is in my command object. But i don't know that how to retrieve the values from command objects and how to iterate through it. Can any one help me ?

        Dim rs As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand("select * from customer")
        SQLREADER = rs.ExecuteReader
        rs.ExecuteNonQuery()

        Imtiaz Imtiaz

        D Offline
        D Offline
        Dan Morris
        wrote on last edited by
        #3

        Try this if you want a data reader: Dim cnn as SqlConnection = New Connection(connectionString) Dim cmd as SqlCommand = New SqlCommand("SELECT * FROM Customer", cnn) Dim rdr as SqlDataReader = cmd.ExecuteReader() 'Now iterate through the reader While rdr.Read() Console.WriteLine(rdr("CustomerName")) End While ... Dan Morris

        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