Question not showing the data in my mysql database. Help?

ReSpade

Member
Joined
Nov 27, 2012
Messages
7
Programming Experience
Beginner
Hello everyone. I am new here. I was recently programing an application that "should" be simple. So far it has proven to be a complete pain to do. The point of this application is to grab data from a myspl database and display it in a table in the application. There is also an add record feature. My current problem is that my application doesn't want to display the data for some reason. I have been staring at it for countless hours to no avail. I know for sure that it does in fact connect to the database though. I debugged it that far. After that I do not know what to do. Here is my complete code minus the database connection specifications...

VB.NET:
Imports MySql.Data.MySqlClientImports System.Data


Public Class Form1
    Dim ds As DataSet
    Dim sqlcon As MySqlConnection
    Dim da As MySqlDataAdapter


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        sqlcon = New MySqlConnection("Server=localhost; Database=prices; Uid=root;")
        sqlcon.Open()


        If sqlcon.State = ConnectionState.Open Then
            Call showData()
            MsgBox("Succesfully connected to the database")
        Else
            MsgBox("error")
        End If
    End Sub


    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        ds = New DataSet
        da = New MySqlDataAdapter("insert into prices (level,cost,item,world,class,type,subtype) values('" & txtLevel.Text & "','" & txtPrice.Text & "','" & txtItem.Text & "','" & txtWorld.Text & "','" & txtClass.Text & "','" & txtType.Text & "','" & txtSubType.Text & ")", sqlcon)
        da.Fill(ds, "prices")
        Call showData()
    End Sub
    Sub showData()


        ds = New DataSet
        da = New MySqlDataAdapter("Select * from prices", sqlcon)
        da.Fill(ds, "prices")


        lvDisplay.Items.Clear()
        If ds.Tables("prices").Rows.Count > 0 Then
            For i As Integer = 0 To ds.Tables("prices").Rows.Count - 1
                With lvDisplay.Items.Add(ds.Tables("prices").Rows(i).Item(0).ToString)
                    .SubItems.Add(ds.Tables("prices").Rows(i).Item(1).ToString)
                    .SubItems.Add(ds.Tables("prices").Rows(i).Item(2).ToString)
                    .SubItems.Add(ds.Tables("prices").Rows(i).Item(3).ToString)
                    .SubItems.Add(ds.Tables("prices").Rows(i).Item(4).ToString)
                    .SubItems.Add(ds.Tables("prices").Rows(i).Item(5).ToString)
                    .SubItems.Add(ds.Tables("prices").Rows(i).Item(6).ToString)
                End With
            Next
        End If


        txtLevel.Text = ""
        txtPrice.Text = ""
        txtItem.Text = ""
        txtWorld.Text = ""
        txtClass.Text = ""
        txtType.Text = ""
        txtSubType.Text = ""
    End Sub
    Private Sub lvDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvDisplay.Click
        txtLevel.Text = lvDisplay.SelectedItems(0).Text
        txtPrice.Text = lvDisplay.SelectedItems(0).SubItems(1).Text
        txtItem.Text = lvDisplay.SelectedItems(0).SubItems(2).Text
        txtWorld.Text = lvDisplay.SelectedItems(0).SubItems(3).Text
        txtClass.Text = lvDisplay.SelectedItems(0).SubItems(4).Text
        txtType.Text = lvDisplay.SelectedItems(0).SubItems(5).Text
        txtSubType.Text = lvDisplay.SelectedItems(0).SubItems(6).Text
    End Sub


    Private Sub lvDisplay_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvDisplay.SelectedIndexChanged


    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


    End Sub
End Class

Can someone help me solve this? That would be great! Thanks for the help in advance.
 
Why do so many people make their lives difficult by using a ListView when they could just use a DataGridView? If you use a DataGridView then you can simply populate a DataTable with the data and then assign it to the DataSource of the grid. There's no code to create the columns or the rows. You can then edit the data in the grid, which you can't with a ListView, or if you want to use TextBoxes, etc, for editing then you simply bind them to the same DataTable and there's again no code required.

So, are you required to use a ListView or can you do it the way it should be done and use a DataGridView?
 
Why do so many people make their lives difficult by using a ListView when they could just use a DataGridView? If you use a DataGridView then you can simply populate a DataTable with the data and then assign it to the DataSource of the grid. There's no code to create the columns or the rows. You can then edit the data in the grid, which you can't with a ListView, or if you want to use TextBoxes, etc, for editing then you simply bind them to the same DataTable and there's again no code required.

So, are you required to use a ListView or can you do it the way it should be done and use a DataGridView?

I can do it either way but i'm not sure I know how to use DataGridView. I have never used it before.
 
Back
Top