Vb.net 检索表中一列的值
我的问题是: 我有两个表帐户和事务日志。 在Accounts表中,它有列Amount,该列是帐户的基本金额。 在Trans Logs表中,它还具有列Amount,该列Amount是对帐户基本金额的额外添加或减去。 我不知道如何检索基本金额来编辑它,然后将其保存回表中。 这意味着我需要通过使用Acc_No来查找右列的值。顺便说一下,我正在使用数据集。 我认为应该是这样的:Vb.net 检索表中一列的值,vb.net,Vb.net,我的问题是: 我有两个表帐户和事务日志。 在Accounts表中,它有列Amount,该列是帐户的基本金额。 在Trans Logs表中,它还具有列Amount,该列Amount是对帐户基本金额的额外添加或减去。 我不知道如何检索基本金额来编辑它,然后将其保存回表中。 这意味着我需要通过使用Acc_No来查找右列的值。顺便说一下,我正在使用数据集。 我认为应该是这样的: Dim Amount as Decimal Amount = *the code to retrieve the base a
Dim Amount as Decimal
Amount = *the code to retrieve the base amount*
Amount = Amount + txtAmount.Text
*the code to save the new amount back to Accounts table*
谢谢大家! dim似乎表明您正在使用某些版本的Basic?
Private Sub UpdateAmount(ByVal Acc_No As Integer, ByVal Amt As Double, ByVal Acc_Type As String)
'Retrieve columns from accounts table
Dim cnntStr As String = "Data Source=DUC-91D85F3F8C2\SQLEXPRESS;Initial Catalog=BasicAccounting;Integrated Security=True"
Dim cn As New SqlConnection(cnntStr)
cn.Open()
Dim da As SqlDataAdapter
Dim ds As New Data.DataSet
Dim stmt As String = "SELECT Amount, Acc_Type FROM ACCOUNTS WHERE Acc_No = " & Acc_No
da = New SqlDataAdapter(stmt, cn)
da.Fill(ds, "ACCOUNTS")
'To modify the amount
Dim type As String
type = ds.Tables(0).Rows(0).Item("Acc_Type")
Dim amount As Decimal
amount = ds.Tables(0).Rows(0).Item("Amount")
If type = Acc_Type Then
amount = amount + Amt
ElseIf type <> Acc_Type Then
amount = amount - Amt
End If
'To update the amount
stmt = "UPDATE ACCOUNTS SET Amount = " & amount & " WHERE Acc_No = " & Acc_No
da = New SqlDataAdapter(stmt, cn)
da.Fill(ds, "ACCOUNTS")
da.Update(ds, "ACCOUNTS")
End Sub