Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,
I am doing an application using VB 2010 and access 2003 as back end.

I have created four tables as CashDepositReg, CashDepositTran, CashWidrawReg and CashWidrawTran.

Which is register tables and its transactions tables.
If user deposit money it will save in CashDepositReg and its transaction details will save in
CashDepositTran.
If user withdraw his deposited money those info will save in CashWidrawReg and CashWidrawTran.
Now my problem is, if user cancels his cash withdraw in CashWidrawReg the withdraw amt should update in CashDepositTran.WidrawAmt against each respective transactions.

Table: CashDepositReg
CRegID | CashDepDate | UserID | DepAmt
1 | 09/Mar/2013 | 123 | 10500

Table: CashDepositTran
CTranID | CRegID | CashDepDate | UserID | DepAmt | WidrawAmt
1 | 1 | 09/Mar/2013 | 123 | 10000 | 10000
2 | 1 | 09/Mar/2013 | 123 | 500 | 500

Table: CashWidrawReg
WRegID | CashWidDate | UserID | WidrawAmt
15 | 10/Mar/2013 | 123 | 10500

Table: CashWidrawTran
WTranID | WRegID | CTransID | CashWidDate | UserID | WidrawAmt
17 | 15 | 1 | 10/Mar/2013 | 123 | 10000
18 | 15 | 2 | 10/Mar/2013 | 123 | 500
Posted
Comments
Kschuler 29-Apr-13 11:30am    
What is the question? If you are supposed to update a value, then update it. Where are you stuck? What code do you have and is it erroring out? If so, what is the error message? If not, then what is it doing and what do you want it to do?
tnncprojects 30-Apr-13 14:05pm    
Hello Kschuler, Thanks for you comments....
I need to update table rows by another table row by reference same id's (Please go thru my question) and i have the below code to fetch the required values to update those values in another table.

Dim conn123 As New OleDbConnection("My connection string")

Dim Query As String = "SELECT (B.WidrawAmt) AS test FROM CashWidrawReg A INNER JOIN CashWidrawTran B on A.WRegID = B.WRegID WHERE A.WRegID = 15"

Dim Cmd As New OleDbCommand(Query, conn123)

Dim Dr As OleDbDataReader
Dim outPutString As String = ""

conn123.Open()

Dr = Cmd.ExecuteReader
With Dr
If .HasRows = True Then
While .Read
outPutString += .Item(0).ToString & ","
End While
End If
End With
Dr.Close()

Output
10000,500,

And I also update the table using the below query...

Dim conn1 As New OleDbConnection("My Connection String")

Dim query1 As String = "UPDATE CashDepositTran SET CashDepositTran.WidrawAmt = CashDepositTran.WidrawAmt - '" & outPutString & "' WHERE CashDepositTran.CTranID IN (1,2)"

Dim Cmd1 As New OleDbCommand(query1, conn1)
conn1.Open()
With Cmd1
.ExecuteNonQuery()
End With
Cmd1.Dispose()
conn1.Close()

After excuting the UPDATE query its updating by concatenate the output values.

Table: CashDepositTran (Before UPDATE Query)
CTranID | CRegID | CashDepDate | UserID | DepAmt | WidrawAmt
1 | 1 | 09/Mar/2013 | 123 | 10000 | 10000
2 | 1 | 09/Mar/2013 | 123 | 500 | 500

10000500 and updating in each rows as below

Table: CashDepositTran (After UPDATE Query)
CTranID | CRegID | CashDepDate | UserID | DepAmt | WidrawAmt
1 | 1 | 09/Mar/2013 | 123 | 10000 | -9990500
2 | 1 | 09/Mar/2013 | 123 | 500 | -10000000

Here the values are getting concatenate and getting updated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900