Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataTable.Compute Problem 1

Status
Not open for further replies.

ceyhorn

Programmer
Nov 20, 2003
93
US
I have been racking my brains for hours over this.

Code:
totalNewHours = myTable.Compute("SUM(Time)", "FundSourceIni = AH")

This code is suppose to take the sum of all the rows in "Time" while adding up only rows with "AH" in the FundSourceIni column. I keep getting "column AH does not exist. Any ideas to why? Thanks in advance.

Chris
 
Chris,
The column type where AH is is probably of type string, isn't it? If yes, then add single quotes around AH and it should work fine:
Code:
totalNewHours = myTable.Compute("SUM(Time)", "FundSourceIni = [COLOR=red][b]'[/b][/color]AH[COLOR=red][b]'[/b][/color]")
JC

Oh Wow!!! I was unaware of all the smileys available here at tek-tips.
[rockband]
 
But what if I want to pass in a variable like:

Code:
totalNewHours = myTable.Compute("SUM(Time)", "FundSourceIni = Variable")

Thanks again
 
It works the same way... simply do this:
Code:
totalNewHours = myTable.Compute("SUM(Time)", "FundSourceIni = [COLOR=red][b]'[/b][/color]" + Variable + "[COLOR=red][b]'[/b][/color]")
I'm assuming you're using C#. If our using Visual Basic .NET, the concatenation operator is & as opposed to the plus sign (+).

JC

Oh Wow!!! I was unaware of all the smileys available here at tek-tips.
[rockband]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top