10
ADO NET

Ado net

Embed Size (px)

DESCRIPTION

ADO.NET IN VISUAAL BASIC VB

Citation preview

Page 1: Ado net

ADO NET

Page 2: 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( )

Page 3: Ado net

IMPORT

Import system.data

Import system.data.sqlclient

Page 4: Ado net

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()

Page 5: Ado net

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)

Page 6: Ado net

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)

Page 7: Ado net

UPDATE

Update command is used to modify the value of RECORDS of the table' Update the database. da.Update(ds, “PERSON")

Page 8: Ado net

DELETE

Delete command is used to delete a particular RECORD from the table.

Page 9: Ado net

DELETE A RECORD SYNTAX

' Delete a record. row = dt.Select("CategoryName = 'MyCategory'") row.Delete( )

Page 10: Ado net

WRITING THE DATA BACK TO THE DATABASEda.Update(ds, “PERSON")' Close the database connection.

cn.Close( )