Displaying Data Table Records in Datagridview using VB.Net

0
400

This tutorial is all about Displaying Data table records in Datagridview using VB.Net, Displaying Data table records in Datagridview using VB.Net is one way of developing a system. It shows what data are stored in your database. So let’s get started.

  • First is open the Visual Basic, Select File on the menu, then click New and create a new project.
  • Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK

  • Then design your form like this just like what I’ve shown you below.
    Add a DataGridview and a Button from the toolbox.

  • Go to code view the add this following code above the Public Class Form.
  1. Imports System.Data.OleDb
  • Then, Add this following declarations below the Public Class Form.
  1. 'Change C: to the location of your database file.
  2. Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Clive\Documents\Visual Studio 2008\clive projects\Displaydata\Displaydata\bin\Debug\Items.accdb"
  3. Dim Myconnection As OleDbConnection
  4. Dim dbda As OleDbDataAdapter
  5. Dim dbds As DataSet
  6. Dim tables As DataTableCollection
  7. Dim source As New BindingSource
  • After that, Go back to design and click the Button and add this following codes.
  1. Myconnection = New OleDbConnection
  2. Myconnection.ConnectionString = connString
  3. dbds = New DataSet
  4. tables = dbds.Tables
  5. dbda = New OleDbDataAdapter("Select * from [tblitems]", Myconnection)
  6. dbda.Fill(dbds, "tblitems")
  7. Dim view As New DataView(tables(0))
  8. source.DataSource = view
  9. DataGridView1.DataSource = view
  • Finally,  Click F5 to run the program.

Output:

Displaying Data Table records in Datagridview using VB.Net

If you have any questions or suggestions about Displaying Data Table records in Datagridview using VB.Net please contact me through our contact page.

Download Displaying Data Table records in Datagridview using VB.Net Source code Here

 

Readers might read also:

Facebook Comments
(Visited 459 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here