Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pervasive SQL v12 with Visual Basic .NET

Status
Not open for further replies.

TGrahmann

Programmer
Feb 19, 2015
43
US
Hello, all. I am fairly new to both Visual Basic .NET and Pervasive SQL. I Was wondering if anyone could give me a rundown on how to conduct a SELECT statement and insert the result (it will be a single result) into a VB.net Variable. Thanks!
 
Here are the basic steps:
1. Create (or verify) a PSQL database exists for the data you intend to access.
2. Add a reference to the Pervasive.Data.SqlClient.DLL to your VB.NET project.
3. Use the PsqlConnection to open a connection to the PSQL database.
4. Use PsqlCommand to execute the SQL (SELECT) statement.
5. Read the resultset using a PsqlDataReader and save the value to your variable.

Here's a simple C# app from many years ago that I posted. I'm looking for VB.NET.
Code:
using System;
using System.Data;
using Pervasive.Data.SqlClient;
using System.IO;

namespace SimpleADONetTest
{
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
			try
			{
				PsqlConnection conn=new PsqlConnection("ServerDSN=demodata;UID=;PWD=;Server=localhost;");
				conn.Open();
				Console.WriteLine("ServerName: " + conn.ServerName.ToString());
				Console.WriteLine("ServerDSN: " + conn.ServerDSN.ToString());
				// Create a SQL command
				string strSQL = "select * from class";
				PsqlCommand DBCmd = new PsqlCommand(strSQL, conn);
				PsqlDataReader myDataReader;
				myDataReader = DBCmd.ExecuteReader();
				Console.WriteLine("FieldCount: " + myDataReader.FieldCount.ToString());
				while (myDataReader.Read())
				{
					for (int i=0;i<myDataReader.FieldCount;i++)
					{
						Console.WriteLine("Field " + i.ToString() + ": " + myDataReader[i].ToString());
					}
				}
				myDataReader.Close();
				conn.Close();
				Console.WriteLine("Press Enter to continue");
				Console.ReadLine();
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message);
				Console.ReadLine();
			}
			
		}
	}
}

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top