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

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
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
ww_w___._j_a__v_a___2___s___.__c_o__m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.