ARTICLE

Data Grid Control in VB.Net

Posted by Deepak Kumar Verma Articles | Visual Basic 2010 February 10, 2011
Data Grid Control is used to show the data in tabular form. This article is also easily demonstrate that how to connect with a database.
Download Files:
 
Reader Level:

Data Grid Control is used to show the data in tabular form. This article is also easily demonstrate that how to connect with a database.

Please consider following :

Database used : "Microsoft Office Access 2007 (.accdb)"

Database Name : "Employee.accdb"

Code :

Imports System.Data.OleDb

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Connecting to the Employee.accdb Database

        Dim Con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=.\\Employee.accdb")

        ' Create a Data

        Dim Dad As OleDbDataAdapter = New OleDbDataAdapter("Select * from Table1", Con)

        ' Create a Data Set

        Dim Dst As DataSet = New DataSet

        ' Fill the Database

        Dad.Fill(Dst, "Employee")

        ' Attach DataSet to DataGrid

        DataGrid.DataSource = Dst.Tables(0)

        ' Code to count and show the field in "Table1" Table

        Con.Open()

        Dim Cmd As New System.Data.OleDb.OleDbCommand()

        Cmd.Connection = Con

        Cmd.CommandText = "Select * from Table1"

        Dim Drd As OleDbDataReader

        Drd = Cmd.ExecuteReader

        Label1.Text = "Number of Fields in Table1 :: " & Drd.FieldCount.ToString

        Drd.Close()

        Con.Close()

    End Sub

End Class

 

Output :

 

output.gif

Login to add your contents and source code to this article
share this article :
post comment
 

please help to change data grid view column header back color

Posted by naresh babu Apr 14, 2011
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