Load data from database into DataGrid : DataGrid « Database ADO.net « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Database ADO.net » DataGridScreenshots 
Load data from database into DataGrid
Load data from database into DataGrid

 Imports System
 Imports System.Drawing
 Imports System.Collections
 Imports System.ComponentModel
 Imports System.Windows.Forms
 Imports System.Data
 Imports System.Data.SqlClient

 
Public Class MainClass

    Shared Sub Main(  )
        Application.Run(New ADOForm1() )
    End Sub

   
End Class

  Public Class ADOForm1
     Inherits System.Windows.Forms.Form

     Private components As System.ComponentModel.Container
     Friend WithEvents EmployeeDataGrid As _
         System.Windows.Forms.DataGrid

     Public Sub New(  )
         InitializeComponent(  )

         Dim connectionString As String ="server=(local)\SQLEXPRESS;" & _
          "integrated security=sspi;database=MyDatabase"


         Dim commandString As String = _
           "Select FirstName, LastName from Employee"

         Dim myDataAdapter As _
         New SqlDataAdapter(commandString, connectionString)
         Dim myDataSet As New DataSet(  )
         myDataAdapter.Fill(myDataSet, "Employee")

         ' bind the DataSet to the grid
         EmployeeDataGrid.DataSource = _
             myDataSet.Tables("Employee").DefaultView

     End Sub 'New

     Private Sub InitializeComponent(  )
         Me.components = New System.ComponentModel.Container(  )
         Me.EmployeeDataGrid = New System.Windows.Forms.DataGrid(  )
         EmployeeDataGrid.Location = New System.Drawing.Point(4824)
         EmployeeDataGrid.Size = New System.Drawing.Size(368160)
         EmployeeDataGrid.TabIndex = 0
         Me.Text = "ADOFrm1"
         Me.AutoScaleBaseSize = New System.Drawing.Size(513)
         Me.ClientSize = New System.Drawing.Size(464273)
         Me.Controls.Add(EmployeeDataGrid)
     End Sub 

 End Class 
           
       
Related examples in the same category
1.DataGrid: Load data table with data readerDataGrid: Load data table with data reader
2.Click button to Update DataGridClick button to Update DataGrid
3.Load result set from 'select' command into a DataGridLoad result set from 'select' command into a DataGrid
4.Use datagrid to display table schemaUse datagrid to display table schema
5.Bind data into a data grid and do the updateBind data into a data grid and do the update
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.