ADO.NET:
ADO.NET (ActiveX Data base Object) is
Microsoft's platform for data access in its new .NET Framework. ADO.NET is
scalable, interoperable, and familiar enough to ADO developers. At most basic
level , ADO.NET is a set of framework namespaces:
- System.Data
- Sytem.Data.common
- System.Data.SqlClient
- Sytem.Data.OleDbClient
- System.Data.SqlType
System.Data Namespace:
The System.Data namespace contain many of the
objects upon which ADO.NET is built. This is where you will find out the
DataSet, Datatable, DataReflection, and DataView
objects.
Step to Crate DataSet:
There are some steps to create the DataSet,
that are:
- Open the visual studio2008.
- Select new project Window form
- Drag and Drop DataGridViewer to window form.
- Drag and Drop DataSet to window form. it give me message.
- Double click in Data set icon.
- Write these code:
Public Class Form1
Private Sub
Form1_Load(ByVal sender
As System.Object, ByVal e
As System.EventArgs)
Handles MyBase.Load
Dim ds As New DataSet("DataSetSample")
' Create Table
Dim dt
As New DataTable("DataTable")
' Create Column
Dim cl1
As New DataColumn("Column1")
cl1.DataType = GetType(Integer)
Dim cl2 As New DataColumn("Column2")
cl2.DataType = GetType(String)
' Add column to table
dt.Columns.Add(cl1)
dt.Columns.Add(cl2)
' Add DataTable to DataSet
ds.Tables.Add(dt)
' Step to add DataRow
' Create new row
Dim dr
As DataRow
dr = ds.Tables("DataTable").NewRow
dr("Column1") = 1
dr("Column2") =
"Welcome to vb.net Sample code"
' Add Row1
ds.Tables("DataTable").Rows.Add(dr)
' If you can use array of datarow.
Dim drArray(1)
As DataRow
drArray(0) = ds.Tables(0).NewRow
drArray(0)("Column1") = 2
drArray(0)("Column2") =
"Show easy sample code"
ds.Tables("DataTable").Rows.Add(drArray(0))
drArray(1) = ds.Tables(0).NewRow
drArray(1)("Column1") = 3
drArray(1)("Column2") =
"Easy to understand"
ds.Tables("DataTable").Rows.Add(drArray(1))
' binddata to gridview
Me.DataGridView1.DataSource =
ds.Tables("DataTable").Copy()
End Sub
End Class
OutPut:
