我們希望更新SQL Server 2012數據庫中的數據,其中值從 更改爲ASP.Net DetailsView
上的值。我會想更新使用使用強類型數據集更新ASP.Net/VB.Net數據庫
- 數據庫中的一個強類型DataSet稱爲
DataSetParentsDetails
- 一個TableAdapter稱爲
ParentsDetailsTableAdapter
- 一個DataTable名爲
ParentsDetails
。
這些是使用DataSet Designer創建的。
這是從代碼的代碼隱藏用於弄清楚我們要更新到數據庫中的文件數量:
Protected Sub DetailsViewDetails_ItemCommand(sender As Object, e As System.Web.UI.WebControls.DetailsViewCommandEventArgs)
Dim dcmAmountToAdjust As Decimal
Dim StrSqlStatement As String
Select Case e.CommandName
Case "Add"
Case "Edit"
dcmOriginalRegistrationFee = GetValueFromLabelRegistrationFee()
Case "Delete"
Case "Update"
dcmNewRegistrationFee = GetValueFromTextBoxRegistrationFee()
dcmAmountToAdjust = dcmNewRegistrationFee - dcmOriginalRegistrationFee
' Update the tuition balance in the parent's data.
'-------------------------------------------------
StrSqlStatement =
"Update Students " & _
"Set RegistrationCode = RegistrationCode + @AmountToAdjust " & _
"Where StudentID = @ID"
' Code to update the database goes here.
'---------------------------------------
End Select
End Sub
我敢肯定,這是問過很多次,但我可以」 t找到一個很好的例子來說明如何使用StrSqlStatement
中的查詢來通過強類型的DataSet更新數據庫。
我在這裏丟失了一點,還是會使用標準的SqlConnection和SqlCommand來完成這項工作?您可以傳入參數並指定數據類型,大小以及所需的所有內容。 – Sean
感謝您的回覆。是的,如果這是更新數據庫的最簡單方法。請你可以展示一個編碼樣本?謝謝。 –