Can't create a query

103 views Asked by At

I've googled this a lot and can't find and answer (probably because it's so rudimentary).

I'm creating a simple VB application to search for items in a pervasive database. I've managed to connect to the database, but can't figure out how to create and execute a query. I'm quite new to this, but here's what I have.

Dim idText As String
Dim myPsqlConnection As PsqlConnection = New PsqlConnection()
myPsqlConnection.ConnectionString = "ServerName=FILESERVER;ServerDSN=myDSN"
myPsqlConnection.Open()
'run query here, but I don't know how!
myPsqlConnection.Close()

I'm looking for a way to execute a simple 'select * from table where feild=something' kind of query, no inserts, deletes, or updates.. read only.

1

There are 1 answers

1
mirtheil On BEST ANSWER

You need to look at PsqlCommand and PsqlDataReader objects.
A very simple VB.NET app that executes a query is:

Imports Pervasive.Data.SqlClient

Module Module1

    Sub Main()
        Dim conn As New PsqlConnection("ServerDSN=DEMODATA")
        Dim cmd As New PsqlCommand("select id,name from class", conn)
        conn.Open()
        Dim dr As PsqlDataReader
        dr = cmd.ExecuteReader
        While (dr.Read)
            Console.WriteLine("ID: " & dr("id").ToString() & " -- " & "Name: " & dr("name").ToString())
        End While
        dr.Close()
        conn.Close()

    End Sub

End Module