Simple code Visual Basic 2008 express edition for displaying

vb , sms , mySQL , display voting result , visual basic 2008 express edition Pasir Gudang, Malaysia
  • 10 years ago

    Hi there,

    I had wrote a simple program for displaying the voting result from sms, all the sms will be saved in mySQL database. I previous uses this code and it is working fine, but for now, suddenly just unable to work properly. When i click on the start button but it is unable to retreive the latest data from the database. Can anyone please help? * Here is my code* ** Imports MySql.Data.MySqlClient Imports MySql.Data Imports System.Data Imports System.Data.Odbc.OdbcDataAdapter Imports System.Data.Odbc.OdbcDataReader Imports System.Data.Odbc Imports System Imports System.IO Imports System.Configuration Imports MySql.Data.MySqlClient.MySqlDataReader Imports System.Drawing.Size Imports System.Drawing

    Public Class Form1 Dim myCommand As New MySqlCommand Dim myAdapter As New MySqlDataAdapter Dim myData As New DataTable Dim myData2 As New DataTable Dim myData3 As New DataTable Dim myData4 As New DataTable Dim myData5 As New DataTable Dim myData6 As New DataTable Dim SQL As String Dim SQL2 As String Dim SQL3 As String Dim SQL4 As String Dim SQL5 As String Dim SQL6 As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Visible = False
        Label2.Visible = False
        Label3.Visible = False
        Label6.Visible = False
        Label7.Visible = False
        Label8.Visible = False
        Label11.Visible = False
        Label10.Visible = False
        Label9.Visible = False
        Label20.Visible = False
        Label19.Visible = False
        Label18.Visible = False
        Label17.Visible = False
        Label16.Visible = False
        Label15.Visible = False
        Label14.Visible = False
        Label13.Visible = False
        Label12.Visible = False
        btnstart.Enabled = False
        btnedit.Enabled = False
    
    End Sub
    
    
    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=;"
    

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.” - Edward V Berard