• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

go thru all the records

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.
Thanks
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")

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

        DBConn.Close()
0
Steven
Asked:
Steven
  • 2
1 Solution
 
Bob LearnedCommented:
1) What database type is PsqlConnection?

2) You could simplify this with a data adapter:

3) What .NET do you have?

Bob
0
 
DhaestCommented:
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
Try
myConnection.Open()
'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
dr.Close()
myConnection.Close()
Catch e As Exception
End Try
End Sub

End Class
0
 
DhaestCommented:
Oops, posted a way too late :)
Please answer the questions from TheLearnedOne
0
 
StevenAuthor Commented:
Excellent Dhaest  it work they way I need it. Thanks a million.  (Im using pervasive and asp.net express)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now