Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to compute results from a column loanGiven from a table empLoan WHERE empID = empID variable. Following is the code

XML
sumObject = this.shahiemsDataSet.empLoan.Compute("SUM(loanGiven)", "empID = " + empID)


The variable empID gets value from datagridview cells.(Works fine)

I get the following error 'Cannot find Coloumn[EMP005]'.

Yes the record exists in the database.
Yes I have checked without filter. (It works fine).
Posted

Found the solution.

sumObject = this.shahiemsDataSet.empLoan.Compute("SUM(loanGiven)", "empID = ' " + empID"'")
 
Share this answer
 
Please see https://msdn.microsoft.com/en-us/library/system.data.datatable.compute%28v=vs.110%29.aspx[^]

C#
public Object Compute(
    string expression,
    string filter
)



it means you have to pass both parameter as string But you are passing string, string+int

C#
public Object Compute(
    string ,
    string +int
)


your second parameter also should be string type as

"empID = " + empID + "'"
 
Share this answer
 
v3

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