Save same value in table as of its Primary Key Column

Posted by Sharpcnet under C# on 1/21/2014 | Points: 10 | Views : 549 | Status : [Member] | Replies : 1
I have two forms - Credit.aspx & Debit.aspx. Both use the same table. The former saves only credit records and the latter-debit.

ID int
RefID int
Credit Decimal
Debit Decimal
ID is an AutoIdentity column.
Using C# to save data.
Only, When saving a credit record, I would like to save the ID as also its RefID. The Credit form can save single or many records at a time. If the data type was GUID, we would have known beforehand and is easy, but now is not the case.

The expected output would be
ID RefID   Credit  Debit
9 9 2.0 0.0
10 10 3.0 0.0
11 9 0.0 1.0
12 9 0.0 4.0
So, is it possible.
Getting the max(ID) doesnt seem like a good idea to me.


Posted by: Vuyiswamb on: 4/17/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

You Table design is wrong , i am sorry to say this. but that is how it is. Now this is Accounting , you are triying to combine the the Debit and Credit into one table which will be a problem again when you need to Calculate the Balance. This is one you should do it.

1) For each Credit or Debit there must be two records inserted

2) You must have a Transaction_Id that group them together

3) Know when to use -(Positive) and Negative (+)

Thank you for posting at Dotnetfunda

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response