go thru all the records

Posted on 2007-07-23
Last Modified: 2013-12-20
Hello experts
I like to go thru all the records that Im getting from the select statement. But I dont know how to do it.
P.S I know it can be done with a While but Im not sure how to do this.

  Dim DBConn As PsqlConnection
        Dim command As New PsqlCommand
        Dim statement As String
        Dim SQLCom As New SqlCommand
        Dim table As New DataTable
        DBConn = New PsqlConnection("ServerDSN=dsn;UID=user;PWD=pass; Server=servername")

        statement = "select NAME from EMPLOYEE"
        command = New PsqlCommand(statement, DBConn)

Question by:Stendor
    LVL 96

    Expert Comment

    by:Bob Learned
    1) What database type is PsqlConnection?

    2) You could simplify this with a data adapter:

    3) What .NET do you have?

    LVL 53

    Accepted Solution

    Looping your dataset:Example with sql-server

    Imports System.Data.SqlClient
    Public Class Form1 Inherits System.Windows.Forms.Form
    Dim myConnection As SqlConnection
    Dim myCommand As SqlCommand
    Dim dr As New SqlDataReader()
    'declaring the objects

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)_
    Handles MyBase.Load
    myConnection = New SqlConnection("server=localhost;uid=sa;pwd=;database=pubs")
    'establishing connection. you need to provide password for sql server
    'opening the connection
    myCommand = New SqlCommand("Select * from discounts", myConnection)
    'executing the command and assigning it to connection
    dr = myCommand.ExecuteReader()
    While dr.Read()
       'reading from the datareader
       MessageBox.Show("discounttype" & dr(0).ToString())
       MessageBox.Show("stor_id" & dr(1).ToString())
       MessageBox.Show("lowqty" & dr(2).ToString())
       MessageBox.Show("highqty" & dr(3).ToString())
       MessageBox.Show("discount" & dr(4).ToString())
    End While
    Catch e As Exception
    End Try
    End Sub

    End Class
    LVL 53

    Expert Comment

    Oops, posted a way too late :)
    Please answer the questions from TheLearnedOne
    LVL 1

    Author Comment

    Excellent Dhaest  it work they way I need it. Thanks a million.  (Im using pervasive and express)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now