Categories
Mastering Development

Why I get this error in Vb.net while connecting mysql “Conversion from string to type ‘Double’ is not valid”?

I tryied the equation separately. It worked. But after I joined, i got the error of conversion. My aim is to get MySql data to the vb.net So I can check some values and develop the project. I have to finish the project within one week and I don’t know how to finish this. If this seems easy please forgive me.

Imports MySql.Data.MySqlClient

Public Class Form3
Dim conn As MySqlConnection
Dim command As MySqlCommand
Dim cmd As MySqlCommand
Dim Da As New MySqlDataAdapter
Dim ds As New DataSet

Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    'To check whether the date is same
    TextBox1.Text = System.DateTime.Now.ToString(("MM/dd/yyyy"))

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    conn = New MySqlConnection
    conn.ConnectionString = "server=localhost;user=root;password=1234;database=attendance"
    Dim reader As MySqlDataReader
    Try
        ds.Clear()
        conn.Open()
        'Checking Subject Now
        cmd = New MySqlCommand("select Subject_Name from dateverification", conn)
        Da = New MySqlDataAdapter(cmd)
        Da.Fill(ds, "dateverification")
        TextBox2.Text = ds.Tables(0).Rows(0).Item(0)

        'Checking Todays Date
        cmd = New MySqlCommand("select Today_Date from dateverification", conn)
        Da = New MySqlDataAdapter(cmd)
        Da.Fill(ds, "dateverification")
        Label1.Text = ds.Tables(0).Rows(0).Item(0)

        'Checking Count1
        cmd = New MySqlCommand("select Count1 from dateverification", conn)
        Da = New MySqlDataAdapter(cmd)
        Da.Fill(ds, "dateverification")
        Label2.Text = ds.Tables(0).Rows(0).Item(0)

        'Checking Count2
        cmd = New MySqlCommand("select Count2 from dateverification", conn)
        Da = New MySqlDataAdapter(cmd)
        Da.Fill(ds, "dateverification")
        Label3.Text = ds.Tables(0).Rows(0).Item(0)

        'If the days are Different, Total days will be counted and Date will be updated
        If Label1.Text <> TextBox1.Text Then
            Label1.Text = System.DateTime.Now.ToString(("yyyy-MM-dd"))
            Label2.Text = Label2.Text + 1
            Dim quary1 As String
            quary1 = "UPDATE attendance.dateverification SET Today_Date = '" & Label1.Text & "' , Count1 = '" & Label2.Text & "' WHERE Subject_Name = '" & TextBox3.Text & "'; "
            command = New MySqlCommand(quary1, conn)
            reader = command.ExecuteReader
            MessageBox.Show("Welcome to New Day")

        Else
        'If the date are equal, then the number of counts which register wasopen in same day will be increased
            Label3.Text = Label3.Text + 1
            Dim quary1 As String
            quary1 = "UPDATE attendance.dateverification SET Count2 = '" & Label3.Text & "' WHERE Subject_Name = '" & TextBox3.Text & "'; "
            command = New MySqlCommand(quary1, conn)
            reader = command.ExecuteReader
            MessageBox.Show("You are still on the same day")

        End If

        Dim quary As String
        quary = "UPDATE attendance.dateverification SET Subject_selected = '" & TextBox3.Text & "' WHERE Subject_Name = '" & TextBox3.Text & "'; "
        command = New MySqlCommand(quary, conn)
        reader = command.ExecuteReader
        conn.Close()

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        conn.Dispose()

    End Try

Leave a Reply

Your email address will not be published. Required fields are marked *