ARTICLE

ADO.NET in VB.NET

Posted by Munesh Sharma Articles | ADO.NET in VB.NET March 31, 2011
In this article we will discus about the ADO.NET and Also describe the process to create DataSet.
Download Files:
 
Reader Level:

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:

                 Data-Set-output.gif

 

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor