Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I want to insert debit and credit values into the database table based on Combobox Selected Values.My ComboBox consists of Cr. and Dr. items and the Database table columns are Id,Name,Debit and Credit.When I select Debit from ComboBox and enter amount 1000 (in textbox) then the table Debit column should display as 1000Dr and the Credit column should be null like wise If I select Credit from ComboBox and enter amount 500 then the Credit column should display as 500Cr.(Debit column should be null).

Here is Example
Id       Name      Debit           Credit
 1        Ram         1000Dr.        NULL
 2        Ravan       NULL           500Cr.

How to write code for this?

Thanks in advance.
Posted
Updated 19-Aug-15 7:39am
v2
Comments
Sergey Alexandrovich Kryukov 19-Aug-15 9:38am    
What have you tried so far?
—SA
CHill60 19-Aug-15 12:33pm    
If you post what you have tried so far we have a far better chance of helping you. For example, you have mentioned a textbox - SQL Server does not have textboxes, so you must be using something else to enter the data.

1 solution

As i suggested in the comments to your past question[^], you have to write proper data structure.

Credit and debit should be stored in the same column! If user chooses Dr., save negative numeric value. That's all!

A sql command might look like:
SQL
INSERT INTO TableName (Credit_Debit) VALUES(@creditDebit)


Follow this link to find out how to call this query: SqlParameterCollection.AddWithValue Method[^]
 
Share this answer
 

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