名称'CONNECTION'未声明

时间:2014-02-15 08:40:42

标签: mysql vb.net

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        If ListView1.Items.Count > 0 Then

            For i = ListView1.Items.Count - 1 To 0 Step -1
                If ListView1.Items(i).Checked = True Then

                    strSQL = "DELETE FROM tbl_hbill WHERE ID = '" & ListView1.Items(i).Text & "'"
                    Dim da As New MySqlDataAdapter(strSQL, CONNECTION)
                    da.Fill(ds)

                End If
            Next i
        End If
        List()

1 个答案:

答案 0 :(得分:1)

确保您拥有连接变量

像这样

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

   Dim CONNECTION As MySqlConnection = New MySqlConnection
   CONNECTION.ConnectionString = "connectionstring"
   CONNECTION.Open()

        If ListView1.Items.Count > 0 Then

            For i = ListView1.Items.Count - 1 To 0 Step -1
                If ListView1.Items(i).Checked = True Then

                    strSQL = "DELETE FROM tbl_hbill WHERE ID = '" & ListView1.Items(i).Text & "'"
                    Dim da As New MySqlDataAdapter(strSQL, CONNECTION)
                    da.Fill(ds)

                End If
            Next i
        End If
        List()
End Sub

connectionstring