Introduction ADO.NET provides an object oriented paradigm for database access. In the code, the objects are instantiated from class definitions. The classes are grouped into containers called namespaces. It’s a convenience, not a requirement to create namespace references.
The Namespaces System.Data.SqlClient System.Data.OleDb System.Data.OracleClient
INSERT, UPDATE and DELETE
Now we using namepaces and make connection with database through the connection string
Connection string has server, database, user id and password
Dim myConnectionString As String
myConnectionString = "Database=netpub;server=192.168.1.28;user id=root; pwd="
Dim myConnection As New SqlConnection(myConnectionString) Hear the SqlConnection is used to make a connection with the particuler database Make a Query to pass through connection
Dim myInsertQuery As String = "INSERT INTO user ( username, pwd, rights) Values('test', 'test', 1)"
Dim myCommand As New SqlCommand(myInsertQuery) myCommand.Connection = myConnection
Hear The SqlCommand is used pass the query through the SqlConnection
myConnection.Open() myCommand.ExecuteNonQuery() myCommand.Connection.Close()
SELECT Make a connection and pass the Query
Dim myConnection As New SqlConnection(myConnectionString) Dim mySelectQuery As String = "SELECT * from file where file_id not in(select file_id from sample where status='0')" Dim myCommand As New SqlCommand(mySelectQuery, myConnection) myConnection.Open()
We should use DataReader to retrieve data, its gets the copy of database as readonly format Dim myReader As SqlDataReader
now we make connection between SqlCommand and SqlDataReader Through ExecuteReader command
myReader = myCommand.ExecuteReader()
While myReader.Read() MsgBox(myReader.GetValue(1)) End While The Read() function is used to fetch the data from DataReader, and GetValue() class used to fetch the exact field from the Database using 0,1,2..... myReader.Close() myConnection.Close()
Summary
This Article may useful to Indent to performing the .Net DataBase
|
| Author: Puja Sharma 24 Sep 2008 | Member Level: Gold Points : 2 |
Hi Nivas,
Very useful article. Each aspectof database connectivity is described very clearly.
Varun
|