If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > voting display system cannot refresh

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-27-10, 07:25
SweeKee SweeKee is offline
Registered User
 
Join Date: Aug 2010
Posts: 6
Cool 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
voting display system cannot refresh-untitled-1.jpg  
Reply With Quote
  #2 (permalink)  
Old 08-27-10, 09:57
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
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? ***
Reply With Quote
Reply

Tags
display voting, retrieve data from mysql, vb2008, voting system

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On