2 Replies - 1449 Views - Last Post: 16 May 2010 - 05:19 AM Rate Topic: -----

#1 Albert Pinto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-May 10

How to Display All my data from the Tables in vb.net

Posted 16 May 2010 - 04:21 AM

Hi Sir,
I'm trying to develop a windows application, I'm using VB.NET(Visual Studio 2005) and MySql database.
Wanted a code to display all my data in Datagrid (In a Tabular form.
Is This A Good Question/Topic? 0
  • +

Replies To: How to Display All my data from the Tables in vb.net

#2 Albert Pinto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-May 10

Re: How to Display All my data from the Tables in vb.net

Posted 16 May 2010 - 04:35 AM

Hi, My Code to display Data in a Datagrid is:

Imports System.Data.Odbc

Public Class Data


Private Sub Data_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim connString As String = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=krishna;UID=root;PASSWORD=atmark;OPTION=3"



Dim myConnection As OdbcConnection = New OdbcConnection
myConnection.ConnectionString = connString

myConnection.Open()

Dim sql As String = "SELECT * from company_client_details"
Dim da As New OdbcDataAdapter(sql, myConnection)
Dim CmdB As New OdbcCommandBuilder(da)
Dim ds As New DataSet
da.Fill(ds, "company_client_details")
Dim dv As New DataView
dv.Table = ds.Tables("company_client_details")
DataGridView1.DataSource = dv

End Sub

Private Sub KrishnaDataSetBindingSource_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataSetBindingSource.CurrentChanged

End Sub

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

End Sub
End Class



The tables are displayed but records are not visible
Pls Help
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How to Display All my data from the Tables in vb.net

Posted 16 May 2010 - 05:19 AM

Well I know this doesn't help but I didn't see anything wrong with your code so I set used a local database and changed the code to fit it and ran it and received the information as expected.

The Datagridview was populated with the table.

Are you receiving any errors?

Here's the code using OLEDB for the Access database I used.
        Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Applications\PersonnelDB.mdb"
        Dim myConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection
        myConnection.ConnectionString = connString
        myConnection.Open()

        Dim sql As String = "SELECT * from employee"
        Dim da As New OleDb.OleDbDataAdapter(sql, myConnection)
        Dim CmdB As New OleDb.OleDbCommandBuilder(da)
        Dim ds As New DataSet
        da.Fill(ds, "employee")
        Dim dv As New DataView
        dv.Table = ds.Tables("employee")
        DataGridView1.DataSource = dv
        myConnection.Close()


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1