Many are not aware that they can download and use free of cost, Microsoft Visual Basic 2008 express edition free of cost. Here is the link:
Note that there are simple lessons on the page listed above.
Filed under: visual basic | Leave a Comment »
Many are not aware that they can download and use free of cost, Microsoft Visual Basic 2008 express edition free of cost. Here is the link:
Note that there are simple lessons on the page listed above.
Filed under: visual basic | Leave a Comment »
You can use the SQL Update statement to issue a command that changes a record or group of records. The below code demonstrates how to do this.
Option Explicit
Dim CN As Connection
Dim comobj As Command
Private Sub Form_Load()
Set CN = New Connection
Set comobj = New Command
With CN
.ConnectionString = “Integrated Security=SSPI;Initial Catalog=FinAccounting;Data Source=SYS1”
.Provider = “SQLOLEDB”
.Open
End With
With comobj
.ActiveConnection = CN
.CommandText = “UPDATE AccountsTable SET AccountName =’Main Creditor1′ WHERE AccountCode=’C001′”
.Execute
End With
Filed under: Uncategorized | Leave a Comment »
We can use the SQL Insert statement to issue a command that will add a new record in a data source. The following code demonstrates how to use SQL Statements to Insert a record using CommandObject execute method in Visual Basic.
Option Explicit
Dim CN As Connection
Dim comobj As Command
Private Sub Form_Load()
Set CN = New Connection
Set comobj = New Command
With CN
.ConnectionString = “Integrated Security=SSPI;Initial Catalog=FinAccounting;Data Source=SYS1”
.Provider = “SQLOLEDB”
.Open
End With
With comobj
.ActiveConnection = CN
.CommandText = “INSERT INTO AccountsTable(AccountCode,AccountName,AccountCat) values(‘C001’,’Creditor1′,’1′)”
.Execute
End With
End Sub
Filed under: visual basic | Leave a Comment »
You can also have multiple Command objects accessing data from a data source, using the same Connection object.
General Declaration Section
Dim CN As Connection
Dim comobj As Command
Dim comTobj As Command
Private Sub Form_Load()
Set CN = New Connection
Set comobj = New Command
Set comTobj = New Command
With CN
.ConnectionString = “Integrated Security=SSPI;Initial Catalog=FinAccounting;Data Source=SYS1”
.Provider = “SQLOLEDB”
.Open
End With
With comobj
.ActiveConnection = CN
.CommandText = “Select * from AccountsTable”
.Execute
End With
With comTobj
.ActiveConnection = CN
.CommandText = “Select * from TranTable”
.Execute
End With
End Sub
Note : The database server treats two different connections as two separate entities, though they may be referring to the same data source. As a result, it assigns separate resources for both the Connection objects. This can adversely affect the performance of your application.
Filed under: visual basic | Leave a Comment »
A Command object is used to define an SQL command that you can execute on a data source.A Command object requires a Connection object. Data returned as a result of the execution of a command is accepted and stored in a Recordset object. The following diagram shows the relation between a Command object and a Connection object.
With reference to Command Object properties, the below mentioned three properties are essential.
The following code example demonstrates how to use the CommandObject in Visual Basic. If the CommandText is an SQL statement, then CommandType need not be mentioned. In the General Declaration section, declare the Command object, comobj as shown below.
Option Explicit
Dim CN As Connection
Dim comobj As Command
In the Form_Load event, initialize the ActiveConnection and CommandText properties of the Command object, comobj as shown below. We need to call the Execute method of the Command object.
Private Sub Form_Load()
Set CN = New Connection
Set comobj = New Command
With CN
.ConnectionString = “Integrated Security=SSPI;Initial Catalog=FinAccounting;Data Source=SYS1”
.Provider = “SQLOLEDB”
.Open
End With
With comobj
.ActiveConnection = CN
.CommandText = “Select * from AccountsTable”
.Execute
End With
End Sub
Filed under: Uncategorized | Tagged: Visual Basic CommandObject | Leave a Comment »
Creating a Connection object in Visual Basic
The Connection object establishes a connection to a data source. It allows your application to pass client information, such as username and password to the database for validation.
Steps:
Set a reference to the ADO Object Library
Before you can use ADO in your Visual Basic application, you must first set a reference to the Microsoft ActiveX Data Objects 2.0 Liobrary. To create a reference to the ADO Object Library:
Declare a Connection object
Once you have made a reference to the ADO object library, you can declare Connection object in your application. The following code example code declares and instantiates a new Connection object.
Dim CN As Connection
Set CN = New Connection
Specify an OLE DB data provider
Once you have instantiated a Connection object, you must specify an OLE DB data source provider. You do this by setting the Provider property. The following code specifies the Microsoft SQL Server OLEDB data provider.
CN.Provider = “SQLOLEDB”
Pass Connection information
The final step before establishing a connection to a data source is to specify the connection information. You do this by setting the Connection object’s ConnectionString property. Connection string arguments are provider specific, are passed directly to the provider, and are not processed by ADO.
The following connection string arguments are used with the SQL Server OLE DB provider.
Connection argument
Integrated Security
Data Source
Initial Catalog
Description
SSPI
Name of the remote server
Database name in the external data source
With CN
.ConnectionString = “Integrated Security=SSPI;Initial Catalog=FinAcc;Data Source=SYS1”
.Provider = “SQLOLEDB”
End With
Integrated Security is for Windows Authentication
Connecting to a Data Source
Once we have specified an OLE DB data provider and have passed the ConnectionString information, you use the Open method to establish a connection to the data source.
The following example code creates a connection to a Microsoft SQL Server database called FinAcc on the server SYS1 using SQL Server OLE DB provider. Type the following code in the frmAccountDetails form.
Option Explicit
Dim CN As Connection
Private Sub Form_Load()
Set CN = New Connection
With CN
.ConnectionString = “Integrated Security=SSPI;Initial Catalog=FinAcc;Data Source=SYS1”
.Provider = “SQLOLEDB”
.Open
End With
End Sub
Closing a connection
CN.Close
Set CN=Nothing
To release the connection to a databse, we need to execute the Close method of the Connection object, and set the Connection object to Nothing. If you choose to release the Connection object whenever the form gets unloaded, then the above code needs to be written in the Unload event of the from.
For more information on connection strings in visual basic.net and c# .net click here.
Filed under: visual basic | Tagged: Creating a Connection object | Leave a Comment »
The following topics illustrate how to use ADO Objects to perform the basic database operations using Visual Basic and SQL Server.
Each of the above tasks can be used to retrieve data, modification of data, inserting data, navigation and deleting of data. By familiarizing yourself with the above tasks you can handle almost any requirement to handle data.
Filed under: visual basic | Tagged: ADO Objects | Leave a Comment »
Establish Connection – Execute Commands – Use Data Reader
In this method, Connection is established to the data source, a Command is used to access and execute commands against the data source, and Data Reader is used to display data to the -application. We will discuss how the above can be achieved. Consider the following code. This code is a part of an application which has one data entry screen and one database. The application when compiled displays data from a database.
This code accomplishes the following tasks.
1.Establish the connection with the FinAccounting database with Connection object.
2.Execute the command (Select statement) with the Command object.
3.The data will be read by the data reader object and display the contents of first record in the textboxes.
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim str_sql_user_select As String = “SELECT * FROM AccountsTable”
Dim str_connection As String = “Data Source=KRISHNA\VSDOTNET;Integrated Security=SSPI;Initial Catalog=FinAccounting”
Dim mycon As SqlConnection
Dim comUserSelect As SqlCommand
Dim myreader As SqlDataReader
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
MyBase.Load
mycon = New SqlConnection(str_connection)
‘Instantiate the commands
comUserSelect = New SqlCommand(str_sql_user_select, mycon)
TextBox1.Text = “ “
TextBox2.Text = “ “
mycon.Open()
myreader = comUserSelect.ExecuteReader
If (myreader.Read = True) Then
TextBox1.Text = myreader(0)
TextBox2.Text = myreader(1)
Else
MsgBox(“You have reached eof”)
End If
End Sub
End Class
Now let us see which part of the code accomplishes the above tasks.
1.Establish the connection with the FinAccounting database with Connection object.
The following tasks are accomplished by the code given under this section.
a.Declare the string variable ‘str_sql_user_select’ to hold the SQL statement.
b.Declare string variable ‘str_connection ’ to hold the Connection string.
c.Declare the Connection object ‘mycon’ .
d.Declare the command object ‘comUserSelect’.
e.Declare the Data reader object ‘myreader’ .
f.Instantiate the connection object.
Dim str_sql_user_select As String = “SELECT * FROM AccountsTable”
Dim str_connection As String = “Data Source=AB\VSDOTNET;Integrated Security=SSPI;Initial Catalog=finaccounting”
Dim mycon As SqlConnection
Dim comUserSelect As SqlCommand
Dim myreader As SqlDataReader
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
mycon = New SqlConnection(str_connection)
2.Execute the command (Select statement ) with the Command object
The following tasks are accomplished by the code given under this section.
a.Instantiate the Command object.
b.Initialize the textbox controls.
c.Open the Connection.
comUserSelect = New SqlCommand(str_sql_user_select, mycon)
TextBox1.Text = “ “
TextBox2.Text = “ “
mycon.Open()
3.The data will be read by the Data Reader object and display the contents of first record in the textboxes.
The following tasks are accomplished by the code given under this section.
a. Execute the command and return rows in DataReader.
b. Display the contents of the first record in the textbox controls. The statement myreader(0)
indicates the first field of the current record.
myreader = comUserSelect.ExecuteReader
If (myreader.Read = True) Then
TextBox1.Text = myreader(0)
TextBox2.Text = myreader(1)
Else
MsgBox(“You have reached eof”)
End If
Filed under: visual basic | Tagged: Connection String | 1 Comment »
In order to understand the application development process, it is helpful to grasp some of the key concepts upon which Visual Basic is built. As Visual Basic is a Windows development language, familiarity with the Windows programming environment is necessary. Understanding the windows programming environment can be classified into the following two steps:
a. How Windows Works: Windows, Events and Messages
b. Understanding the Event-Driven Model
a. How Windows Works: Windows, Events and Messages
Think of a windows as simply a rectangular region with its own boundaries. You are probably already aware of different types of windows: an Explorer window in Windows 95, a document window within your word processing program, or a dialog box that pops up to remind you of an appointment. While these are the most common examples, there are actually many other types of windows. A command button is a window. Icons, text boxes, option buttons and menu bars are all windows.
b. Understanding the Event-Driven Model
In an event-driven environment the application executes different code sections in response to events. Events can be triggered by the user’s actions, by messages from the system or other applications, or even from the application itself.
The sequence of these events determines the sequence in which the code executes, thus the path through the application’s code differs each time the program runs. Because you can’t predict the sequence of events, your code must make certain assumptions about the “state of the world” when it executes. When you make assumptions (for example, that an entry field must contain a value before running a procedure to process that value), you should structure your application in such a way as to make sure that the assumption will always be valid (for example, disabling the command button that starts the procedure until the entry field contains a value). Typing the text in a text box cause the text box’s Change event to occur. This would cause the code (if any) contained in the Change event to execute. If you assumed that this event would only be triggered by user interaction, you might see unexpected results. It is for this reason that it is important to understand the event-driven model and keep it in mind when designing your application.
Filed under: visual basic | Tagged: Programming Concepts | Leave a Comment »
A collection of Visual Basic Links:
Visual Basic Tutorial – Beginners
Visual Basic Tutorials for Newbies
First Visual Basic 6 Program Designing and Writing
Gary Beene’s Visual Basic Tutorials (popular)
Visual Basic journey tips tricks and tutorials
DevCentral – Visual Basic Tutorials
Visual Basic Info. covered on every aspect
Visual Basic Business Objects – A Primer
VB- Beginners and Intermediate Tutorials
Visual Basic Resource: 20 Tutorials
From Visual Basic Call VC++ .DLL
Connecting HTML Help to Visual Basic Programs
How to Create super compact Super Fast C++ Dll for VB
Passing picture from C++ DLL to a VB PicBox
How to write C DLL’s and call them from Visual Basic
Context Sensitive Help for Visual Basic
Optimize SQL Queries in Visual Basic
XML and Visual Basic
Professional Visual Basic 6 XML
XML for Visual Basic Developers (PPT)
Visual Basic and UML (Unified Modeling Language)
Visual Basic Debugging
Jaz Lichy’s Visual Basic Standards
Effective Visual Basic coding standards enforcement.
VB Law Enforces Coding Standards
Visual Basic Programming Standards
Visual Basic VB Source Code Archives
Programmers Heaven – Visual Basic Zone
Visual Basic E-Books and References
New Stuff in Visual Basic 6.0 (Documents = 2.5 MB)
New Stuff in Visual Basic 6.0 (Examples = 630 KB)
Visual basic (VB) and SQL Server (Documents == 4.00 MB)
VB and SQL Server (Examples – 709 KB)
3 Chapters from Visual Basic for Kids
Optimize Size and Speed of Visual Basic Applications
Tim’s Visual Basic 5 Tips and Tricks
Visual Basic: Tips & Tricks (Must)
vbVision – Visual Basic Tips and Tricks
Tapping into Data with the VB .NET DataBuilder Classes
Executing a Package from Visual Basic
Web Services in Visual Basic .Net
Implementing Interfaces in Visual Basic.NET
Phone Number Dialer – Code Sample
Thin Client Programming – Learn all the basics
Visual Basic .NET as a Fully Object-Oriented Language
Create Your Own Visual Basic Add-Ins
Using the Winsock Control in Client/Server Applications
Drawing Fast Polygons / Graphics with VB5/6
Random Numbers and Tic Tac Toe with Visual Basic .NET
To Avoid Common Database Programming Mistakes in VB
Visual Basic Barcode FAQ & Tutorial
Visual Basic(Microsoft) Databases FAQs
Frequently Asked Questions About VB
Visual Basic Dot Net
Filed under: Uncategorized | Tagged: Visual Basic Links | Leave a Comment »