单击非相关按钮时出现SQL错误

时间:2017-11-22 23:46:43

标签: mysql vb.net

我目前在系统出现问题时遇到错误,提示“Column_Name不明确”#39; ,'连接状态=打开'每当我按下一个与我的SQL查询完全无关的按钮时。它是唯一一个显示错误的按钮,但困扰我的是这个按钮不相关,不像其他按钮一样,点击时会激活SQL查询。我也在我的查询中使用了前缀,所以'不明确的'错误不应该存在。此外,我也一直保持连接状态关闭,因此连接状态=打开'错误有点令人困惑

PS:我对计时器有疑问,但我不认为这是错误的原因,因为这个按钮仅用于编辑已经放在DataGridView上的日期,而不是数据库本身。这个唯一的按钮显示错误。

这是按钮的代码:

Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click

    Dim rateprice, hourspaid, totalprice, count As Integer

    BilliardHall.load_timerangeedit() 'SQL Query For Checking Available Dates Only and Fills up the Variable 'Count' if there are Results'

    count = Label122.Text

    x = MetroMessageBox.Show(Me, "Are you sure?", "Edit Hours Paid", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

    If x = vbYes Then

        If TextBox4.Text = Nothing Then
            MetroMessageBox.Show(Me, "Please Fill the Hours Paid Text Field", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        ElseIf TextBox4.Text = "0" Then
            MetroMessageBox.Show(Me, "Hours Paid must be Greater than 0", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Else
            rateprice = Label108.Text
            hourspaid = TextBox4.Text
            totalprice = rateprice * hourspaid

            If count > 0 Then
                MetroMessageBox.Show(Me, "There are currently Reserved Subscriptions on the Given Schedule", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                count = 0
            ElseIf DateTimePicker3.Value <= Now.AddMinutes(-1) Then
                MetroMessageBox.Show(Me, "Starting Date and Time cannot be lower than the Current Date and Time", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                SubscriptionListGrid.Item(4, SubscriptionListGrid.CurrentRow.Index).Value = TextBox4.Text
                SubscriptionListGrid.Item(5, SubscriptionListGrid.CurrentRow.Index).Value = totalprice
                SubscriptionListGrid.Item(6, SubscriptionListGrid.CurrentRow.Index).Value = Format(DateTimePicker3.Value, "MMMM dd, yyyy  hh:mm tt")
                SubscriptionListGrid.Item(7, SubscriptionListGrid.CurrentRow.Index).Value = Format(DateTimePicker3.Value.AddHours(hourspaid), "MMMM dd, yyyy  hh:mm tt")

                MetroMessageBox.Show(Me, "Hours Paid has been Updated", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information)

            End If


        End If


    Else

    End If

以下是&#39; BilliardHall.load_timerangeedit()&#39;的代码。功能:

Public Function load_timerangeedit()

    MysqlConn.ConnectionString = ServerString
    Dim READER As MySqlDataReader

    Try
        MysqlConn.Open()
        Dim query As String

        query = "SELECT DISTINCT(ratedemand.ratedemand_id),playground.playground_id,playground.playground_name FROM bnb.ratedemand,bnb.playground WHERE ratedemand.playground_id = playground.playground_id AND ((ratedemand.ratedemand_datestart BETWEEN '" & Format(Admin_Menu.DateTimePicker3.Value, "yyyy-MM-dd HH:mm:ss tt") & "' AND '" & Format(Convert.ToDateTime(Admin_Menu.Label121.Text), "yyyy-MM-dd HH:mm:ss tt") & "' OR ratedemand.ratedemand_dateend BETWEEN '" & Format(Admin_Menu.DateTimePicker3.Value, "yyyy-MM-dd HH:mm:ss tt") & "' AND '" & Format(Convert.ToDateTime(Admin_Menu.Label121.Text), "yyyy-MM-dd HH:mm:ss tt") & "') OR (ratedemand.ratedemand_datestart < '" & Format(Admin_Menu.DateTimePicker3.Value, "yyyy-MM-dd HH:mm:ss tt") & "' AND ratedemand.ratedemand_dateend > '" & Format(Convert.ToDateTime(Admin_Menu.Label121.Text), "yyyy-MM-dd HH:mm:ss tt") & "')) AND ratedemand.playground_id = (SELECT playground.playground_id FROM bnb.playground WHERE playground.playground_name ='" & Admin_Menu.Label107.Text & "') AND ratedemand.rate_category = 'Billiard' AND (ratedemand.ratedemand_status = 'On Going' or ratedemand.ratedemand_status = 'Reserved')"
        COMMAND = New MySqlCommand(query, MysqlConn)
        READER = COMMAND.ExecuteReader

        Dim count As Integer
        count = 0

        While READER.Read
            count = count + 1
        End While

        MysqlConn.Close()

        Admin_Menu.Label122.Text = count

    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        MysqlConn.Dispose()

    End Try


    Return True
End Function

这是我在计时器#1中的函数代码:

Public Function load_billiardqueuetable(dgrid As DataGridView, billiardqueuecomboplayarea As ComboBox, billiardqueuecombostatus As ComboBox, billiardqueuedtp1 As DateTimePicker, billiardqueuedtp2 As DateTimePicker, rdbilliardqueuetoday As RadioButton, rdbilliardqueuefuture As RadioButton)
    MysqlConn.ConnectionString = ServerString
    Dim dbDataSet As New DataTable
    Dim SDA As New MySqlDataAdapter

    Dim bSource As New BindingSource

    Try
        MysqlConn.Open()

        Dim query As String

        If Not billiardqueuecomboplayarea.Text = "All Play Areas" And Not billiardqueuecombostatus.Text = "All" And rdbilliardqueuetoday.Checked = True Then
            query = "SELECT ratedemand.sales_code as 'Confirmation Code', playground.playground_name as 'Play Area', rate.rate_name as 'Rate', ratedemand.sales_customername as 'Customer Name', ratedemand.ratedemand_hour as 'Hours Paid', DATE_FORMAT(ratedemand.ratedemand_datestart, '%M %d, %Y %h:%i %p') as 'Start', DATE_FORMAT(ratedemand.ratedemand_dateend, '%M %d, %Y %h:%i %p') as 'End', CONCAT(LPAD(TIMESTAMPDIFF(HOUR,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend), 2, 0), ':', LPAD(MOD(TIMESTAMPDIFF(MINUTE,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend),60), 2, 0) ) as 'Time', ratedemand.ratedemand_status as 'Status' FROM bnb.ratedemand,bnb.playground,bnb.rate WHERE ratedemand.playground_id = playground.playground_id AND ratedemand.rate_id = rate.rate_id AND (ratedemand.ratedemand_date BETWEEN '" & Format(billiardqueuedtp1.Value, "yyyy-MM-dd HH:mm:00") & "' AND '" & Format(billiardqueuedtp2.Value, "yyyy-MM-dd HH:mm:59") & "'  ) AND ratedemand.playground_id = (SELECT playground.playground_id FROM bnb.playground WHERE playground.playground_name = '" & billiardqueuecomboplayarea.Text & "') AND ratedemand.ratedemand_status ='" & billiardqueuecombostatus.Text & "' AND ratedemand.rate_category='Billiard' ORDER BY ratedemand.ratedemand_id DESC"
        ElseIf Not billiardqueuecomboplayarea.Text = "All Play Areas" And Not billiardqueuecombostatus.Text = "All" And rdbilliardqueuefuture.Checked = True Then
            query = "SELECT ratedemand.sales_code as 'Confirmation Code', playground.playground_name as 'Play Area', rate.rate_name as 'Rate', ratedemand.sales_customername as 'Customer Name', ratedemand.ratedemand_hour as 'Hours Paid', DATE_FORMAT(ratedemand.ratedemand_datestart, '%M %d, %Y %h:%i %p') as 'Start', DATE_FORMAT(ratedemand.ratedemand_dateend, '%M %d, %Y %h:%i %p') as 'End', CONCAT(LPAD(TIMESTAMPDIFF(HOUR,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend), 2, 0), ':', LPAD(MOD(TIMESTAMPDIFF(MINUTE,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend),60), 2, 0) ) as 'Time', ratedemand.ratedemand_status as 'Status' FROM bnb.ratedemand,bnb.playground,bnb.rate WHERE ratedemand.playground_id = playground.playground_id AND ratedemand.rate_id = rate.rate_id AND (ratedemand.ratedemand_date BETWEEN '" & Format(billiardqueuedtp1.Value, "yyyy-MM-dd 00:00:00") & "' AND '" & Format(billiardqueuedtp2.Value, "yyyy-MM-dd 23:59:59") & "' ) AND ratedemand.playground_id = (SELECT playground.playground_id FROM bnb.playground WHERE playground.playground_name = '" & billiardqueuecomboplayarea.Text & "') AND ratedemand.ratedemand_status ='" & billiardqueuecombostatus.Text & "' AND ratedemand.rate_category='Billiard' ORDER BY ratedemand.ratedemand_id DESC"
        ElseIf Not billiardqueuecomboplayarea.Text = "All Play Areas" And billiardqueuecombostatus.Text = "All" And rdbilliardqueuetoday.Checked = True Then
            query = "SELECT ratedemand.sales_code as 'Confirmation Code', playground.playground_name as 'Play Area', rate.rate_name as 'Rate', ratedemand.sales_customername as 'Customer Name', ratedemand.ratedemand_hour as 'Hours Paid', DATE_FORMAT(ratedemand.ratedemand_datestart, '%M %d, %Y %h:%i %p') as 'Start', DATE_FORMAT(ratedemand.ratedemand_dateend, '%M %d, %Y %h:%i %p') as 'End', CONCAT(LPAD(TIMESTAMPDIFF(HOUR,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend), 2, 0), ':', LPAD(MOD(TIMESTAMPDIFF(MINUTE,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend),60), 2, 0) ) as 'Time', ratedemand.ratedemand_status as 'Status' FROM bnb.ratedemand,bnb.playground,bnb.rate WHERE ratedemand.playground_id = playground.playground_id AND ratedemand.rate_id = rate.rate_id AND (ratedemand.ratedemand_date BETWEEN '" & Format(billiardqueuedtp1.Value, "yyyy-MM-dd HH:mm:00") & "' AND '" & Format(billiardqueuedtp2.Value, "yyyy-MM-dd HH:mm:59") & "' ) AND ratedemand.playground_id = (SELECT playground.playground_id FROM bnb.playground WHERE playground.playground_name = '" & billiardqueuecomboplayarea.Text & "') AND ratedemand.rate_category='Billiard' ORDER BY ratedemand.ratedemand_id DESC"
        ElseIf Not billiardqueuecomboplayarea.Text = "All Play Areas" And billiardqueuecombostatus.Text = "All" And rdbilliardqueuefuture.Checked = True Then
            query = "SELECT ratedemand.sales_code as 'Confirmation Code', playground.playground_name as 'Play Area', rate.rate_name as 'Rate', ratedemand.sales_customername as 'Customer Name', ratedemand.ratedemand_hour as 'Hours Paid', DATE_FORMAT(ratedemand.ratedemand_datestart, '%M %d, %Y %h:%i %p') as 'Start', DATE_FORMAT(ratedemand.ratedemand_dateend, '%M %d, %Y %h:%i %p') as 'End', CONCAT(LPAD(TIMESTAMPDIFF(HOUR,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend), 2, 0), ':', LPAD(MOD(TIMESTAMPDIFF(MINUTE,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend),60), 2, 0) ) as 'Time', ratedemand.ratedemand_status as 'Status' FROM bnb.ratedemand,bnb.playground,bnb.rate WHERE ratedemand.playground_id = playground.playground_id AND ratedemand.rate_id = rate.rate_id AND (ratedemand.ratedemand_date BETWEEN '" & Format(billiardqueuedtp1.Value, "yyyy-MM-dd 00:00:00") & "' AND '" & Format(billiardqueuedtp2.Value, "yyyy-MM-dd 23:59:59") & "' ) AND ratedemand.playground_id = (SELECT playground.playground_id FROM bnb.playground WHERE playground.playground_name = '" & billiardqueuecomboplayarea.Text & "') AND ratedemand.rate_category='Billiard' ORDER BY ratedemand.ratedemand_id DESC"
        ElseIf billiardqueuecomboplayarea.Text = "All Play Areas" And Not billiardqueuecombostatus.Text = "All" And rdbilliardqueuetoday.Checked = True Then
            query = "SELECT ratedemand.sales_code as 'Confirmation Code', playground.playground_name as 'Play Area', rate.rate_name as 'Rate', ratedemand.sales_customername as 'Customer Name', ratedemand.ratedemand_hour as 'Hours Paid', DATE_FORMAT(ratedemand.ratedemand_datestart, '%M %d, %Y %h:%i %p') as 'Start', DATE_FORMAT(ratedemand.ratedemand_dateend, '%M %d, %Y %h:%i %p') as 'End', CONCAT(LPAD(TIMESTAMPDIFF(HOUR,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend), 2, 0), ':', LPAD(MOD(TIMESTAMPDIFF(MINUTE,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend),60), 2, 0) ) as 'Time', ratedemand.ratedemand_status as 'Status' FROM bnb.ratedemand,bnb.playground,bnb.rate WHERE ratedemand.playground_id = playground.playground_id AND ratedemand.rate_id = rate.rate_id AND (ratedemand.ratedemand_date BETWEEN '" & Format(billiardqueuedtp1.Value, "yyyy-MM-dd HH:mm:00") & "' AND '" & Format(billiardqueuedtp2.Value, "yyyy-MM-dd HH:mm:59") & "' ) AND ratedemand.ratedemand_status ='" & billiardqueuecombostatus.Text & "' AND ratedemand.rate_category='Billiard' ORDER BY ratedemand.ratedemand_id DESC"
        ElseIf billiardqueuecomboplayarea.Text = "All Play Areas" And Not billiardqueuecombostatus.Text = "All" And rdbilliardqueuefuture.Checked = True Then
            query = "SELECT ratedemand.sales_code as 'Confirmation Code', playground.playground_name as 'Play Area', rate.rate_name as 'Rate', ratedemand.sales_customername as 'Customer Name', ratedemand.ratedemand_hour as 'Hours Paid', DATE_FORMAT(ratedemand.ratedemand_datestart, '%M %d, %Y %h:%i %p') as 'Start', DATE_FORMAT(ratedemand.ratedemand_dateend, '%M %d, %Y %h:%i %p') as 'End', CONCAT(LPAD(TIMESTAMPDIFF(HOUR,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend), 2, 0), ':', LPAD(MOD(TIMESTAMPDIFF(MINUTE,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend),60), 2, 0) ) as 'Time', ratedemand.ratedemand_status as 'Status' FROM bnb.ratedemand,bnb.playground,bnb.rate WHERE ratedemand.playground_id = playground.playground_id AND ratedemand.rate_id = rate.rate_id AND (ratedemand.ratedemand_date BETWEEN '" & Format(billiardqueuedtp1.Value, "yyyy-MM-dd 00:00:00") & "' AND '" & Format(billiardqueuedtp2.Value, "yyyy-MM-dd 23:59:59") & "' ) AND ratedemand.ratedemand_status ='" & billiardqueuecombostatus.Text & "' AND ratedemand.rate_category='Billiard' ORDER BY ratedemand.ratedemand_id DESC"
        ElseIf billiardqueuecomboplayarea.Text = "All Play Areas" And billiardqueuecombostatus.Text = "All" And rdbilliardqueuetoday.Checked = True Then
            query = "SELECT ratedemand.sales_code as 'Confirmation Code', playground.playground_name as 'Play Area', rate.rate_name as 'Rate', ratedemand.sales_customername as 'Customer Name', ratedemand.ratedemand_hour as 'Hours Paid', DATE_FORMAT(ratedemand.ratedemand_datestart, '%M %d, %Y %h:%i %p') as 'Start', DATE_FORMAT(ratedemand.ratedemand_dateend, '%M %d, %Y %h:%i %p') as 'End', CONCAT(LPAD(TIMESTAMPDIFF(HOUR,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend), 2, 0), ':', LPAD(MOD(TIMESTAMPDIFF(MINUTE,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend),60), 2, 0) ) as 'Time', ratedemand.ratedemand_status as 'Status' FROM bnb.ratedemand,bnb.playground,bnb.rate WHERE ratedemand.playground_id = playground.playground_id AND ratedemand.rate_id = rate.rate_id AND (ratedemand.ratedemand_date BETWEEN '" & Format(billiardqueuedtp1.Value, "yyyy-MM-dd HH:mm:00") & "' AND '" & Format(billiardqueuedtp2.Value, "yyyy-MM-dd HH:mm:59") & "' ) AND ratedemand.rate_category='Billiard' ORDER BY ratedemand.ratedemand_id DESC"
        ElseIf billiardqueuecomboplayarea.Text = "All Play Areas" And billiardqueuecombostatus.Text = "All" And rdbilliardqueuefuture.Checked = True Then
            query = "SELECT ratedemand.sales_code as 'Confirmation Code', playground.playground_name as 'Play Area', rate.rate_name as 'Rate', ratedemand.sales_customername as 'Customer Name', ratedemand.ratedemand_hour as 'Hours Paid', DATE_FORMAT(ratedemand.ratedemand_datestart, '%M %d, %Y %h:%i %p') as 'Start', DATE_FORMAT(ratedemand.ratedemand_dateend, '%M %d, %Y %h:%i %p') as 'End', CONCAT(LPAD(TIMESTAMPDIFF(HOUR,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend), 2, 0), ':', LPAD(MOD(TIMESTAMPDIFF(MINUTE,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend),60), 2, 0) ) as 'Time', ratedemand.ratedemand_status as 'Status' FROM bnb.ratedemand,bnb.playground,bnb.rate WHERE ratedemand.playground_id = playground.playground_id AND ratedemand.rate_id = rate.rate_id AND (ratedemand.ratedemand_date BETWEEN '" & Format(billiardqueuedtp1.Value, "yyyy-MM-dd 00:00:00") & "' AND '" & Format(billiardqueuedtp2.Value, "yyyy-MM-dd 23:59:59") & "' ) AND ratedemand.rate_category='Billiard' ORDER BY ratedemand.ratedemand_id DESC"
        Else
            query = "SELECT ratedemand.sales_code as 'Confirmation Code', playground.playground_name as 'Play Area', rate.rate_name as 'Rate', ratedemand.sales_customername as 'Customer Name', ratedemand.ratedemand_hour as 'Hours Paid', DATE_FORMAT(ratedemand.ratedemand_datestart, '%M %d, %Y %h:%i %p') as 'Start', DATE_FORMAT(ratedemand.ratedemand_dateend, '%M %d, %Y %h:%i %p') as 'End', CONCAT(LPAD(TIMESTAMPDIFF(HOUR,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend), 2, 0), ':', LPAD(MOD(TIMESTAMPDIFF(MINUTE,ratedemand.ratedemand_datestart,ratedemand.ratedemand_dateend),60), 2, 0) ) as 'Time', ratedemand.ratedemand_status as 'Status' FROM bnb.ratedemand,bnb.playground,bnb.rate WHERE ratedemand.playground_id = playground.playground_id AND ratedemand.rate_id = rate.rate_id AND (ratedemand.ratedemand_date BETWEEN '" & Format(billiardqueuedtp1.Value, "yyyy-MM-dd HH:mm:00") & "' AND '" & Format(billiardqueuedtp2.Value, "yyyy-MM-dd HH:mm:59") & "' ) AND ratedemand.rate_category='Billiard' ORDER BY ratedemand.ratedemand_id DESC"
        End If

        COMMAND = New MySqlCommand(query, MysqlConn)
        SDA.SelectCommand = COMMAND
        SDA.Fill(dbDataSet)
        bSource.DataSource = dbDataSet
        dgrid.DataSource = bSource
        SDA.Update(dbDataSet)

        MysqlConn.Close()




    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        MysqlConn.Dispose()



    End Try

    Return True
End Function

这是我在计时器#2中的函数的代码:

Public Function load_cancelled()

    MysqlConn.ConnectionString = ServerString

    Dim READER As MySqlDataReader

    Try
        MysqlConn.Open()
        Dim query As String


        query = "SELECT * FROM bnb.ratedemand WHERE ratedemand_status = 'Reserved' AND NOW() >= ADDDATE(ratedemand_datestart, INTERVAL 30 MINUTE)"
        COMMAND = New MySqlCommand(query, MysqlConn)
        READER = COMMAND.ExecuteReader

        Dim count As Integer
        count = 0

        If READER.HasRows Then
            While READER.Read
                count = count + 1
            End While
        End If
        MysqlConn.Close()

        If count > 0 Then
            MysqlConn.Open()

            query = "UPDATE bnb.ratedemand SET ratedemand_status = 'Cancelled' WHERE ratedemand_status = 'Reserved' AND NOW() >= ADDDATE(ratedemand_datestart, INTERVAL 30 MINUTE)"
            COMMAND = New MySqlCommand(query, MysqlConn)
            READER = COMMAND.ExecuteReader


            MysqlConn.Close()
        Else

        End If


    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        MysqlConn.Dispose()


    End Try

    Return True
End Function

0 个答案:

没有答案