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:
'Imports MySql.Data.MySqlClient
Imports System.Data.Odbc
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SQL As String
Dim myData As New DataTable
Dim myAdapt As New OdbcDataAdapter
Dim CnMs As OdbcConnection
Dim myComm As New OdbcCommand
CnMs = New OdbcConnection
CnMs.ConnectionString = "DSN=mySQLTest"
Try
CnMs.Open()
SQL = "SELECT prod_code,description,colour FROM materials"
myComm.Connection = CnMs
myComm.CommandText = SQL
myAdapt.SelectCommand = myComm
myAdapt.Fill(myData)
MessageBox.Show(myData.Rows(0).Item(0))
With Me
DGV.AutoGenerateColumns = True
DGV.DataSource = myAdapt
DGV.AutoSize = True
DGV.AutoResizeColumns()
DGV.Refresh()
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Cheers..
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.
Re: datagridview - where o where is my data?
lol..apologies for something so stupid :blush:
No more late nights for me. thanks JM :thumb: