2014-02-15 46 views
0
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

請確保您有連接變量

這樣

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

+0

如何有此? ------>'公共連接爲MySql.data.MySqlClient.MySqlConnection' – Helper101

+0

只需在類名後面加上decleration –