Livaren
Livaren

Reputation: 41

Data grid view showing columns but no data

I can see the columns but not the data, maybe something to do with my code creating a new dataset, but I have no idea, here is my code:

  Private Sub frmClientDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    DGVClient.Columns.Clear()
    objdataadapter.SelectCommand = New MySqlCommand()
    objdataadapter.SelectCommand.Connection = objconnection

    objdataadapter.SelectCommand.CommandType = CommandType.Text
    objdataadapter.SelectCommand.CommandText = "SELECT * FROM Client_Details"
    objdataadapter.Fill(New DataSet)

    DGVClient.ColumnCount = 9
    Call bind_dataset_DGVClient()
    Call count_records()
    rowposition = 0

    DGVClient.DataSource = objdataset
    DGVClient.DataMember = "Client_Details"
End Sub

Any help appreciated, thanks.

Upvotes: 0

Views: 563

Answers (3)

AndyZ
AndyZ

Reputation: 625

I would put everything in an initialise sub and call it before showing the frame, so that the frame shows up when data is ready to be shown. I am not sure and I could not find a fast answer if MySqlDataAdapter's fill() method returns the number of records filled. This would make counting the rows easier.

     Private Sub initialise()
        DGVClient.Columns.Clear() 
        Dim sqlCmd As New MySqlCommand()
        sqlCmd.Connection = objconnection
        sqlCmd.CommandText = "SELECT * FROM Client_Details"
        objdataadapter.SelectCommand = sqlCmd
        objdataadapter.Fill(objdataset)
        rowposition = 0
        DGVClient.DataSource = objdataset.Table(0)
     End Sub

     Private Sub frmClientDetails_Load(ByVal sender As System.Object, ByVal e As   System.EventArgs)  Handles MyBase.Load

     End Sub

Upvotes: 0

OneFineDay
OneFineDay

Reputation: 9024

The DataSource should be set to a DataTable not a DataSet.

Private Sub frmClientDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 Dim ds As New DataSet
 objdataadapter.SelectCommand = New MySqlCommand()
 objdataadapter.SelectCommand.Connection = objconnection
 objdataadapter.SelectCommand.CommandType = CommandType.Text
 objdataadapter.SelectCommand.CommandText = "SELECT * FROM Client_Details"
 objdataadapter.Fill(ds, "Client_Details")
 bind_dataset_DGVClient()
 count_records()
 rowposition = 0

 DGVClient.DataSource = ds.Tables("Client_Details")

End Sub

Upvotes: 1

Lauren
Lauren

Reputation: 333

objdataadapter.Fill(New DataSet) isn't returning anything that you have a reference to. Try this

objdataset = New DataSet
objdataadapter.Fill(objdataset)

If you set a breakpoint right after that you can hover over objdataset and click on the Hour glass icon to see what is in the DataSet.

Upvotes: 0

Related Questions