Creating a VB.NET application with EnterpriseDB

Exclusive offer: get 50% off this eBook here
Small Business Server 2008 – Installation, Migration, and Configuration

Small Business Server 2008 – Installation, Migration, and Configuration — Save 50%

Set up and run Microsoft Small Business Server 2008 making it deliver a big business impact with this book and eBook

$23.99    $12.00
by Jayaram Krishnaswamy | May 2009 | .NET Microsoft

Getting introduced to working with Postgres was described in the recent article, "installation and some basic features of EnterpriseDB". Migration of data from SQL Server 2008 was described in "The migration of a table from SQL Server 2008 to EnterpriseDB". In this tutorial Dr. Jayaram Krishnaswamy shows how you may create a Visual Studio 2008's Windows application to access data on EnterpriseDB. Reading of two previous articles is recommended.

Overview of the tutorial

You will begin by creating an ODBC datasource for accessing data on the Postgres server. Using the User DSN created you will be connecting to the Postgres server data. You will derive a dataset from the table which you will be using to display in a datagrid view on a form in a windows application.

We start with the Categories table that was migrated from MS SQL Server 2008. This table with all of its columns is shown in the Postgres studio in the next figure.

Creating a VB.NET application with EnterpriseDB

Creating the ODBC DSN

Navigate to Start | Control Panel | Administrative Tools | Data Sources (ODBC) to bring up the ODBC Database Manager window.

Creating a VB.NET application with EnterpriseDB

Click on Add.... In the Create New Data Source scroll down to EnterpriseDB 8.2 under the list heading Name as shown.

Creating a VB.NET application with EnterpriseDB

Click Finish. The EnterpriseDB ODBC Driver page gets displayed as shown. Accept the default name for the Data Source(DSN) or, if you prefer, change the name. Here the default is accepted. The Database, Server, User Name, Port and the Password should all be available to you [Read article 1].

Creating a VB.NET application with EnterpriseDB

If you click on the option button Datasource you display a window with two pages as shown. Make no changes to the pages and accept defaults but make sure you review the pages.

Creating a VB.NET application with EnterpriseDB

Click OK and you will be back in the EnterpriseDB Driver window. If you click on the button Global the Global Settings window gets displayed (not shown). These are logging options as the page describes. Click Cancel to the Global Settings window.

Click on the Test button and verify that the connection was successful. Click on the Save button and save the DSN under the list heading User DSN. The DSN EnterpriseDB enters the list of DSN's created as shown here.

Creating a VB.NET application with EnterpriseDB

Create a Windows Forms application and Establish a connection to Postgres

Open Visual Studio 2008 from its shortcut. Click File | New | Project... and open the New Project window. Choose a windows forms project for Framework 2.0. Besides Framework 2.0 you can also create projects in other versions in Visual Studio 2008. In Server Explorer window double click the Connection icon as shown.

Creating a VB.NET application with EnterpriseDB

This brings up the Add Connection window as shown.

Creating a VB.NET application with EnterpriseDB

Click on Change... button to display the Change Data Source window. Scroll up and select Microsoft ODBC Data Source as shown.

Creating a VB.NET application with EnterpriseDB

Click OK. Click on the drop-down handle for the option Use user or system data source name and choose EnterpriseDB you created earlier as shown.

Creating a VB.NET application with EnterpriseDB

Insert User Name and Password and click on the Test Connection button. You should get a connection succeeded message as shown.

Creating a VB.NET application with EnterpriseDB

Click OK on the message screen as well as to the add connection window. The connection appears in the Visual Studio 2008 in the Server Explorer as shown.

Creating a VB.NET application with EnterpriseDB

 

 

Displaying data from the table

Drag and drop a DataGridView under Data in the Toolbox onto the form as shown (shown with SmartTasks handle clicked)

Creating a VB.NET application with EnterpriseDB

Click on Choose Data Source handle to display a drop-down menu as shown below.

Creating a VB.NET application with EnterpriseDB

Click on Add Project Data Source at the bottom. This displays the Choose a Data Source Type page of the Data Source Configuration Wizard.

Creating a VB.NET application with EnterpriseDB

Accept the default datasource type and click Next. In the Choose Your Data Connection page of the wizard choose the ODBC.localhost.PGNorthwind as shown in the drop-down list.

Creating a VB.NET application with EnterpriseDB

Click Next in the page that gets displayed and accept the default to save the connection string to the application configuration file as shown.

Creating a VB.NET application with EnterpriseDB

Click Next. In the Choose Your Database Objects page, expand Tables and choose the categories table as shown. The default Dataset name can be changed. Herein the default is accepted.

Creating a VB.NET application with EnterpriseDB

Click Finish. The DatagridView on Form1 gets displayed with two columns and a row but can be extended to the right by using drag handles to reveal all the four columns as shown. Three other objects PGNorthwindDataSet, CategoriesBindingSource, and CategoriesTableAdapter are also added to the control tray as shown. The PGNorthwindDataset.xsd file gets added to the project.

Creating a VB.NET application with EnterpriseDB

Now build the project and run. The Form 1 gets displayed with the data from the PGNorthwind database as shown.

Creating a VB.NET application with EnterpriseDB

In the design view of the form few more tasks have been added as shown. Here you can Add Query... to filter the data displayed; Edit the details of the columns and you can choose to add a column if you had chosen fewer columns from the original table.

Creating a VB.NET application with EnterpriseDB

For example, Edit Column brings up its editor as shown where you can make changes to the styles if you desire to do so. The next figure shows slightly modified form by editing the columns and resizing the cell heights as shown.

Creating a VB.NET application with EnterpriseDB

Summary

A step-by-step procedure was described to display the data stored in a table in the Postgres database in a Windows Forms application. Procedure to create an ODBC DSN was also described. Using this ODBC DSN a connection was established to the Postgres server in Visual Studio 2008.

Small Business Server 2008 – Installation, Migration, and Configuration Set up and run Microsoft Small Business Server 2008 making it deliver a big business impact with this book and eBook
Published: April 2009
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

If you have read this article you may be interested to view :

About the Author :


Jayaram Krishnaswamy

Jayaram Krishnaswamy studied at the Indian Institute of Science in Bangalore India and Madras University in India and taught at the Indian Institute of Technology in Madras. He went to Japan on a Japanese Ministry of Education Research scholarship to complete his PhD in Electrical Engineering from Nagoya University. He was a Post-Doctoral Fellow at Sydney University in Australia; a Government of India Senior Scientific Officer at the Indian Institute of Science in Bangalore and Indian Institute of Technology at Kanpur; a Visiting Scientist at the Eindhoven Institute of Technology in the Netherlands; a visiting Professor of Physics at the Federal University in Brazil; an Associate Research Scientist at a government laboratory in São Jose dos Campos in São Paulo, Brazil; a visiting scientist at the National Research Council in Ottawa, Canada before coming to USA in 1985. He has also taught and worked at the Colorado State University in Fort Collins and North Carolina State University in Raleigh, North Carolina. He worked with Northrop Grumman Corporation on a number of projects related to high energy electron accelerators and Free Electron Lasers. These projects were undertaken at the Brookhaven National Laboratory in Long Island and in the Physics Department at Princeton University. He has over 80 publications in refereed and non-refereed publications and 8 issued patents. He is fluent in Japanese and Portuguese and lives in Honolulu, Hawaii, USA.

He has been working in IT-related fields since 1997. He was once a Microsoft Certified Trainer in Networking and a Siebel Certified developer. He has worked with several IT related companies, such as the Butler International in their Siebel practice, with several IBM sub-contractors and smaller companies. Presently he is active in writing technical articles in the IT field to many online sites such as http://CodeProject.com, http://APSFree.com, http://DevShed.com, http://DevArticles.com, http://OfficeUsers.org, http://ASPAlliance.com, Egghead Café, http://SSWUG.org, Packt Article Network, http://databasedev.co.uk, http://cimaware.com, and many others. Between 2006 and 2010 he wrote more than 400 articles mostly related to database and web related technologies covering Microsoft, Oracle, Sybase, ColdFusion, Sun, and other vendor products.

He has written four books all published by Packt related to Microsoft Database and Application Development: SQL Server Integration Services Using Visual Studio 2005, Learning SQL Server Reporting Services 2008, Microsoft SQL Azure; Enterprise Application Development, and Microsoft Visual Studio Lightswitch Business Application Development. He regularly writes for his four blogs on Blogger; http://Hodentek.blogspot.com, http://HodentekHelp.blogspot.com, http://HodentekMobile.blogspot.com, and http://HodentekMSSS.blogspot.com. He received the 2011 Microsoft Community Contributor award.

Contact Jayaram Krishnaswamy

Books From Packt

VSTO 3.0 for Office 2007 Programming
VSTO 3.0 for Office 2007 Programming

Drupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQuery

Implementing Microsoft Dynamics NAV 2009
Implementing Microsoft Dynamics NAV 2009

Expert Cube Development with Microsoft SQL Server 2008 Analysis Services
Expert Cube Development with Microsoft SQL Server 2008 Analysis Services

eZ Publish 4: Enterprise Web Sites Step-by-Step
eZ Publish 4: Enterprise Web Sites Step-by-Step

Drupal 6 Social Networking
Drupal 6 Social Networking

Learning SQL Server 2008 Reporting Services
Learning SQL Server 2008 Reporting Services

Small Business Server 2008 – Installation, Migration, and Configuration
Small Business Server 2008 Installation, Migration, and Configuration

 

 

 

 

Your rating: None Average: 3 (1 vote)

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
4
P
1
H
a
F
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software