我正在使用下面提到的代码来更新和删除 datagridview 中的数据。但我无法解决这个问题。删除工作但不更新。
Public Sub CustomerUpdateBatch(ByVal dt As DataTable)
Dim connection As SqlConnection = New SqlConnection(Invoice.GetConnect())
connection.Open()
Try
Dim command As SqlCommand = New SqlCommand("Update_Customer", connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add("@C_ID", SqlDbType.Int, 16, "C_ID")
command.Parameters.Add("@C_Name", SqlDbType.VarChar, 50, "C_Name")
command.Parameters.Add("@C_Address", SqlDbType.VarChar, 50, "C_Address")
command.Parameters.Add("@C_Tel", SqlDbType.VarChar, 50, "C_Tel")
command.Parameters.Add("@C_Fax", SqlDbType.VarChar, 50, "C_Fax")
command.Parameters.Add("@C_Mobile", SqlDbType.VarChar, 50, "C_Mobile")
command.Parameters.Add("@C_Email", SqlDbType.VarChar, 50, "C_Email")
command.Parameters.Add("@C_Tin", SqlDbType.VarChar, 50, "C_Tin")
command.Parameters.Add("@C_Remarks", SqlDbType.VarChar, 50, "C_Remarks")
command.CommandType = CommandType.StoredProcedure
Dim delcommand As SqlCommand = New SqlCommand("Delete_Customer", connection)
delcommand.CommandType = CommandType.StoredProcedure
command.Parameters.Add("@C_ID", SqlDbType.Int, 16, "C_ID")
Dim adapter As SqlDataAdapter = New SqlDataAdapter()
adapter.UpdateCommand = command
adapter.DeleteCommand = delcommand
adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None
adapter.Update(dt)
Catch ex As Exception
Console.WriteLine(ex.Message)
Throw
Finally
connection.Close()
End Try
End Sub