有人可以幫助我處理我的應用程序,我試圖用vb中的datagridview從mysql中刪除一行。由於某種原因,它要麼不能找到名爲user的列,要麼它不能像它應該那樣工作。在datagridview中從mysql中刪除一行vb
這是代碼,我知道它的亂糟糟,有沒有使用的東西,但它不應該影響它。
Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
Try
MySqlConnection.Open()
Catch ex As Exception
End Try
If Me.DataGridView1.Rows.Count > 0 Then
If Me.DataGridView1.SelectedRows.Count > 0 Then
For Each row As DataGridViewRow In DataGridView1.Rows
Dim selUser As String = Me.DataGridView1.CurrentRow.Index
Dim SqlQuery As String = "DELETE FROM Report WHERE user=" & row.DataBoundItem(1).ToString
Dim cmd As New MySqlCommand(SqlQuery, MySqlConnection)
cmd.ExecuteNonQuery()
Dim da As New MySqlDataAdapter("select * from Report", MySqlConnection)
Dim ds As New DataSet
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
Next
End If
End If
End Sub
編輯:現在修復它,謝謝大家誰回答。
您是否在報表中檢查了用戶列? –
在報表中有一個名爲user的列,im sure –
你可以調試,你的'SqlQuery'裏有什麼 –