DataTable.Compute找不到coloumn [英] DataTable.Compute Cannot find coloumn
问题描述
我正在尝试从表empLoan WHERE empID = empID变量中计算列loanGiven的结果。以下是代码
I am trying to compute results from a column loanGiven from a table empLoan WHERE empID = empID variable. Following is the code
sumObject = this.shahiemsDataSet.empLoan.Compute("SUM(loanGiven)", "empID = " + empID)
变量empID从datagridview单元格中获取值。(工作正常)
我收到以下错误'找不到Coloumn [EMP005]'。
是的,记录存在于数据库中。
是的我没有过滤器检查过。 (它工作正常)。
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).
推荐答案
找到解决方案。
Found the solution.
sumObject = this.shahiemsDataSet.empLoan.Compute("SUM(loanGiven)", "empID = ' " + empID"'")
请参阅 https://msdn.microsoft.com/en-us/library/system.data.datatable.compute%28v=vs.110%29.aspx [<一个href =https://msdn.microsoft.com/en-us/library/system.data.datatable.compute%28v=vs.110%29.aspx\"target =_ blanktitle =New Window> ^ ]
Please see https://msdn.microsoft.com/en-us/library/system.data.datatable.compute%28v=vs.110%29.aspx[^]
public Object Compute(
string expression,
string filter
)
这意味着你必须将两个参数作为字符串传递但是你正在传递字符串,字符串+ int
it means you have to pass both parameter as string But you are passing string, string+int
public Object Compute(
string ,
string +int
)
你的第二个参数也应该是字符串类型
empID =+ empID +'
your second parameter also should be string type as
"empID = " + empID + "'"
这篇关于DataTable.Compute找不到coloumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!