-3
我設法編寫此代碼以便從SQL Server數據庫中刪除記錄。無法刪除數據庫中的記錄(SQL服務器)
Private sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
Dim strconnection As String = "Data Source=EASMAR-PC;Initial Catalog=DatabaseConnection;Integrated Security=True;"
Dim _cn As SqlConnection = New SqlConnection(strconnection)
Dim cmd As New SqlCommand
_cn.Open()
Try
_DataSet.Tables(0).Rows(CInt(txtCurrent.Text) - 1).Delete()
Dim adapter As New SqlDataAdapter
Dim cmdBuilder As New SqlCommandBuilder(adapter)
Dim DutyDetails As String = "SELECT ID from tblCustomer"
adapter.SelectCommand = New SqlCommand(DutyDetails, _cn)
adapter.UpdateCommand = cmdBuilder.GetUpdateCommand
adapter.DeleteCommand = cmdBuilder.GetDeleteCommand
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(adapter)
adapter.Update(_DataSet.Tables("0"))
End sub
我錯過了什麼嗎?
我沒有收到任何錯誤。但記錄仍然存在。
任何幫助?
比你:)
我不這麼認爲。我檢查了:/ – user2968155
我看不到你實際上調用了deleteCommand。 –