VB.NET Sample

 

Home
Up

 

Here is a sample script to Take On Customers using Visual Basic.NET.  

It instantiates the OleDBConnection object in the script so there's no need to put database connection controls on the Form.  

Check out these topics in the on-line help or MSDN pages about VB.NET:

 
OleDBConnection

This is used to point to the file containing the database.

 

OleDBCommand

A Command object's Connection property says which connection to use to execute an SQL statement that has been loaded into the CommandText property.  As with any SQL Command, it's a good idea to use them in a Try/Catch block so that errors can be brought to the User's attention.

 
ExecuteScalar

Gets back a single (scalar) result from a table

 

ExecuteNonQuery

Used to execute a Command that does an INSERT or UPDATE without returning a result

 

OpenFileDialog

Pops up the familiar common dialog for a User to navigate to and select a file to open

 

FileOpen, LineInput, EOF

A simple method for processing one record at a time from a sequential file where records are delimited with CrLf

 

String.Split

VB.NET can treat a string as an object.  The Split method uses a specified delimiter to split the string into an array of strings.

 

String.Replace()

In this example, the Replace method is used to 'escape' single quotes in data that will be included in an SQL statement where string values are surrounded by single quotes and a single quote in the middle of the string would cause an error.  A LastName like O'Brien needs to have single quotes doubled, like O''Brien.  

 

String.Format()

This is an easy way to build an SQL query, which need to put single quotes around the values to be INSERTed or UPDATEd.  Use {0}, {1} in the string and what's inside the {} will be replaced with values which follow the string.

 

MsgBox

A MsgBox will pop up to display messages for the script's User.  If a multi-line message is required, separate the lines using vbCrLf (ASCII Chrs 13 & 10)

 

 
Home ] Up ]
Last modified: Saturday October 18, 2003.