Results 1 to 3 of 3

Thread: datagridview - where o where is my data?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    19

    datagridview - where o where is my data?

    Howdy..
    Very new to VB .NET just been trying somethings this afternoon.
    Wanted to simply fill a datagridview.. doesn't seem to matter what I do I get nothing in the grid?? Its just blank, I know there is data in the datatable from the messagebox, but I must be missing something simple for sure. Any help would be much appreciated.

    VB Code:
    1. 'Imports MySql.Data.MySqlClient
    2. Imports System.Data.Odbc    
    3.  
    4. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.         Dim SQL As String
    6.         Dim myData As New DataTable
    7.         Dim myAdapt As New OdbcDataAdapter
    8.         Dim CnMs As OdbcConnection
    9.         Dim myComm As New OdbcCommand
    10.  
    11.         CnMs = New OdbcConnection
    12.         CnMs.ConnectionString = "DSN=mySQLTest"
    13.         Try
    14.             CnMs.Open()
    15.             SQL = "SELECT prod_code,description,colour FROM materials"
    16.             myComm.Connection = CnMs
    17.             myComm.CommandText = SQL
    18.             myAdapt.SelectCommand = myComm
    19.             myAdapt.Fill(myData)
    20.             MessageBox.Show(myData.Rows(0).Item(0))
    21.             With Me
    22.                 DGV.AutoGenerateColumns = True
    23.                 DGV.DataSource = myAdapt
    24.                 DGV.AutoSize = True
    25.                 DGV.AutoResizeColumns()
    26.                 DGV.Refresh()
    27.             End With
    28.         Catch ex As Exception
    29.             MessageBox.Show(ex.Message)
    30.         End Try
    31.     End Sub

    Cheers..

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: datagridview - where o where is my data?

    According to that code you assign a DataAdapter to the DataSource property of the grid. A DataAdapter contains no data. You have to assign the DataTable to the DataSource property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    19

    Re: datagridview - where o where is my data?

    lol..apologies for something so stupid
    No more late nights for me. thanks JM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width