Connection Object
in ADO.NET:
The connection object
is the way ADO.NET's built in data providers to a data source. There are two
connection objects that ship with the ADO.NET. The First OleDbConnection object
is used to Create connection to any valid OLE DB data source and Second
SqlConnection Object is used connect to Microsoft Sql Sever. just as in ADO.NET use the connection strings to connect to various data
sources.
Connection String:
A Connection string
is a semicolon delimited set of name value pairs that define the various
properties of data base connection. Connection String Specify a wide verity of
information, Such as the type of OLE DB provider you are using for your
connection to the database.
Syntax of OLE DB
Connection String:
"Provider=Microsoft.jet.OLEDB.4.0;Data Source=FilePath;Jet
OLEDB;Useri=admin;password= ;"
Connection Object Methods:
There are mainly two methods use in
connection Object:
-
The Open() Method
-
The Close() Method
OLEDB Connection Syntax:
Dim
Conn As OleDbConnection =
New OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;"+
"data source=C:\path;"+"Userid=;"+
"password= ;")
Conn.Open()
Conn.Close()
Sql Server Connection Syntax:
Dim
Conn As SqlConnection =
New
SqlConnection("Initial
Catalog-NorthWind;"+
"Server= (Local);"+"Uid=sa;"+
"password= ;")
Conn.Open()
Conn.Close()