Introduction
Microsoft Visual Studio .NET is a new revolution in computer programming. I
am grateful that Microsoft developed such a great IDE for us. .NET had a lot
of changes to the way we program and what we program in (especially in Visual
Basic). ADO.NET had also a substantial difference from its previous versions.
It's almost a completely new language! :)
I'll show how to create a DB Connection through either OLE or SQL in runtime
using C# as well as VB. Drag and dropping in the IDE is really easy, but there
are times when you need to do it in runtime. SQL and OLE both have their own
namespaces in the .NET Framework. They contain every single object and
method that relate to that type of connection. Of course there is the namespace
for all the General Data handling, which includes objects like the dataset.
OLE = System.Data.OleDB
SQL = System.Data.SqlClient
General Data = System.Data
Step #1: Declare the Connection Object
for OLE:
VB: Friend WithEvents OleConn as new System.Data.OleDB.OleDBConnection()
C#: internal System.Data.OleDB.OleDBConnection OleConn;
for SQL:
VB: Friend WithEvents SqlConn As New System.Data.SqlClient.SqlConnection()
C#: internal System.Data.SqlClient.SqlConnection SqlConn;
Some may wonder why I applied the WithEvents and Friend
or internal modifiers to the objects.
Reason for WithEvents:
-We can create procedures to handle the connection's events...
like the StateChanged event
Reason for internal or Friend:
-Make it available throughout the whole project