Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010
    Posts
    6

    Cool Unanswered: voting display system cannot refresh

    Hi Everyone,

    I had write a simple program using visual basic 2008 express edition for displaying the voting. I am using mySQL as my database, the program have to retrieve data by a SQL statement from my database. Whenever i click on start button, it should be refresh and retrieve the lastest data in mySQL database.

    My problem is that when i load the program, so called a "formload", and click on the start button, it will display the correct data from database, but when i click the button second time, it does not refresh and display the latest data.

    This program is done by me who is a newbie in visual basic, this is the only problem i met, i have to settle it in 1 weeks time. But until now i still cant find the solution, anyone please help me on that?

    My code for my program start button as below

    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
    End
    End Sub

    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstart.Click
    Dim MysqlConn As MySqlConnection

    MysqlConn = New MySqlConnection()


    ' Define the SQL to grab data from table.
    SQL = "SELECT count('content') FROM loglog where content = 'M1'"



    'Connection String
    MysqlConn.ConnectionString = "server=localhost;" _
    & "user id=root;" _
    & "password=;" _
    & "database=vgsmdb"

    ' Try, Catch, Finally
    Try
    MysqlConn.Open()

    myCommand.Connection = MysqlConn
    myCommand.CommandText = SQL

    myAdapter.SelectCommand = myCommand
    myAdapter.Fill(myData)

    DataGridView1.DataSource = myData


    Catch myerror As MySqlException
    MessageBox.Show("Cannot connect to database: " & myerror.Message)
    Finally
    MysqlConn.Close()
    MysqlConn.Dispose()


    End Try

    ' Define the SQL to grab data from table.
    SQL2 = "SELECT count('content') FROM loglog where content = 'M2'"

    'Connection String
    MysqlConn.ConnectionString = "server=localhost;" _
    & "user id=root;" _
    & "password=;" _
    & "database=vgsmdb"

    ' Try, Catch, Finally
    Try
    MysqlConn.Open()

    myCommand.Connection = MysqlConn
    myCommand.CommandText = SQL2

    myAdapter.SelectCommand = myCommand
    myAdapter.Fill(myData2)

    DataGridView2.DataSource = myData2




    Catch myerror As MySqlException
    MessageBox.Show("Cannot connect to database: " & myerror.Message)
    Finally
    MysqlConn.Close()
    MysqlConn.Dispose()

    End Try

    ' Define the SQL to grab data from table.
    SQL3 = "SELECT count('content') FROM loglog where content = 'M3'"

    'Connection String
    MysqlConn.ConnectionString = "server=localhost;" _
    & "user id=root;" _
    & "password=;" _
    & "database=vgsmdb"

    ' Try, Catch, Finally
    Try
    MysqlConn.Open()

    myCommand.Connection = MysqlConn
    myCommand.CommandText = SQL3

    myAdapter.SelectCommand = myCommand
    myAdapter.Fill(myData3)

    DataGridView3.DataSource = myData3



    Catch myerror As MySqlException
    MessageBox.Show("Cannot connect to database: " & myerror.Message)
    Finally
    MysqlConn.Close()
    MysqlConn.Dispose()

    End Try

    ' Define the SQL to grab data from table.
    SQL4 = "SELECT count('content') FROM loglog where content = 'F1'"

    'Connection String
    MysqlConn.ConnectionString = "server=localhost;" _
    & "user id=root;" _
    & "password=;" _
    & "database=vgsmdb"

    ' Try, Catch, Finally
    Try
    MysqlConn.Open()

    myCommand.Connection = MysqlConn
    myCommand.CommandText = SQL4

    myAdapter.SelectCommand = myCommand
    myAdapter.Fill(myData4)

    DataGridView4.DataSource = myData4


    Catch myerror As MySqlException
    MessageBox.Show("Cannot connect to database: " & myerror.Message)
    Finally
    MysqlConn.Close()
    MysqlConn.Dispose()


    End Try

    ' Define the SQL to grab data from table.
    SQL5 = "SELECT count('content') FROM loglog where content = 'F2'"

    'Connection String
    MysqlConn.ConnectionString = "server=localhost;" _
    & "user id=root;" _
    & "password=;" _
    & "database=vgsmdb"

    ' Try, Catch, Finally
    Try
    MysqlConn.Open()

    myCommand.Connection = MysqlConn
    myCommand.CommandText = SQL5

    myAdapter.SelectCommand = myCommand
    myAdapter.Fill(myData5)

    DataGridView5.DataSource = myData5




    Catch myerror As MySqlException
    MessageBox.Show("Cannot connect to database: " & myerror.Message)
    Finally
    MysqlConn.Close()
    MysqlConn.Dispose()

    End Try

    ' Define the SQL to grab data from table.
    SQL6 = "SELECT count('content') FROM loglog where content = 'F3'"

    'Connection String
    MysqlConn.ConnectionString = "server=localhost;" _
    & "user id=root;" _
    & "password=;" _
    & "database=vgsmdb"

    ' Try, Catch, Finally
    Try
    MysqlConn.Open()

    myCommand.Connection = MysqlConn
    myCommand.CommandText = SQL6

    myAdapter.SelectCommand = myCommand
    myAdapter.Fill(myData6)

    DataGridView6.DataSource = myData6


    Catch myerror As MySqlException
    MessageBox.Show("Cannot connect to database: " & myerror.Message)
    Finally
    MysqlConn.Close()
    MysqlConn.Dispose()

    End Try

    Btnsave.Enabled = False
    btnedit.Enabled = True

    End Sub



    I had attach the GUI as well!

    Really appreciates if someone can help me on this..
    Thanks!
    Attached Thumbnails Attached Thumbnails Untitled-1.jpg  

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What do you mean by it does not refresh and display the latest data?

    How do you know the data has been changed? Have you tried running the underlying queries directly against MySQL to make sure it's not the SQL itself that's causing undesirable results? Your bindings look fine, but you don't have anything in there that looks like it would cause an insert/update.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Tags for this Thread

Posting Permissions

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