ADO NET
MAKING CONNECTION TO THE DATABASEOpen a connection to the database. Dim strConnection As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _ & "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb“ Dim cn As OleDbConnection = New OleDbConnection(strConnection) cn.Open( )
IMPORT
Import system.data
Import system.data.sqlclient
METHOD
Code
Dim a As String = "Data Source=C:\Users\Prince raj\Documents\Visual Studio 2010\Projects\rups\rups\qwert.mdf"
Dim cn As SqlConnection = New SqlConnection(a)
cn.Open()
INSERTThis is used to insert data in the table or you can say the row and columns of the database.
Adding a new row to a table in a DataSet is a three-step process:
1. Use the DataTable class's NewRow method to create a new DataRow.
2. Set the values of the columns in the row.
3. Add the new row to the table.
For example, assuming that dt is a DataTable object, and that the table has columns named “name" and “age", this code adds a new row to the table:
' Add a row.
Dim row As DataRow = dt.NewRow( )
row(“name") = “Rupali" row(“age") = 20
dt.Rows.Add(row)
SELECT
Select command is used to perform query in the database.' Create a data adapter object and set its SELECT command. Creating a string object
Dim strSelect As String = "SELECT * FROM person"
CREATING A ADAPTER OBJECT AND PUTTING VALUE OF STRING OBJECT
Dim da As SqlDataAdapter = New SqlDataAdapter(strSelect, cn)
UPDATE
Update command is used to modify the value of RECORDS of the table' Update the database. da.Update(ds, “PERSON")
DELETE
Delete command is used to delete a particular RECORD from the table.
DELETE A RECORD SYNTAX
' Delete a record. row = dt.Select("CategoryName = 'MyCategory'") row.Delete( )
WRITING THE DATA BACK TO THE DATABASEda.Update(ds, “PERSON")' Close the database connection.
cn.Close( )