我正在使用下面提到的代碼來更新和刪除datagridview中的數據。但我無法解決這個問題。刪除正在工作,但沒有更新。如何使用vb.net更新datagridview
公用Sub CustomerUpdateBatch(BYVAL DT作爲數據表)
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
是否Anywhere錯誤?或者什麼都沒有發生?如果你通過sql-server執行它,你的存儲過程是否工作? – Yatrix