|
-
Feb 23rd, 2001, 11:34 AM
#1
Thread Starter
Addicted Member
I am using a DataGrid which bounds to a table (access). The DataGrid has three columns, they all in currency formats. What I would like to see is column3 is the sum of column1 and column2. In other words, after the amount have been enter to column1 and column2, column3 will calculate the sum and show it.
Can this be done in SQL statement or in code ??? Pls provide sample code.
Thank you in advancew
-
Feb 23rd, 2001, 12:13 PM
#2
Junior Member
Try using a sql statement like this:
Code:
select column1, column2, (convert(float,column1) + convert(float,column2)) as column3 from [tblYourTable]
-
Feb 23rd, 2001, 12:41 PM
#3
If you mean that you're gonna have to enter in data in Columns 1 and 2, try the datagrid's AfterColUpdate event. Here's a sample:
Code:
dgSample_AfterColUpdate(ByVal ColIndex as Integer)
Dim number1, number2, sum as Double
If (ColIndex = 0 And (Len(Trim(dgSample.Columns(1).text)) > 0) Or _
If (ColIndex = 1 And (Len(Trim(dgSample.Columns(0).text > 0) Then
number1 = CDbl(dgSample.Columns(0).text)
number2 = CDbl(dgSample.Columns(1).text)
sum = number1 + number2
dgSample.Columns(2).text = sum
End Sub
-
Feb 23rd, 2001, 08:36 PM
#4
Thread Starter
Addicted Member
Hi billyboy,
Can you pls look at your code again... Something is missing I couldn't figure out what.
If (ColIndex = 0 And (Len(Trim(dgSample.Columns(1).text)) > 0) Or _
If (ColIndex = 1 And (Len(Trim(dgSample.Columns(0).text > 0) Then
Is this two If statements or one??? I even add an end if statement and it still give me an error message.
Thanks.
-
Feb 26th, 2001, 10:55 AM
#5
forgot something!
Code:
dgSample_AfterColUpdate(ByVal ColIndex as Integer)
Dim number1, number2, sum as Double
If (ColIndex = 0 And (Len(Trim(dgSample.Columns(1).text)) > 0) Or _
If (ColIndex = 1 And (Len(Trim(dgSample.Columns(0).text)) > 0) Then
number1 = CDbl(dgSample.Columns(0).text)
number2 = CDbl(dgSample.Columns(1).text)
sum = number1 + number2
dgSample.Columns(2).text = sum
End Sub
I forgot to put in the two closing parentheses on the second conditional line..sorry! if you try to copy and paste this it should work.
sorry again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|