How To Convert The DataTable Column type?

后端 未结 3 862
半阙折子戏
半阙折子戏 2020-12-22 05:10

I am trying to implement:

dtGroupedBy.Compute(\"sum(POWER)\",dvv.RowFilter); 

It results of an error:

Invalid usage

3条回答
  •  粉色の甜心
    2020-12-22 05:34

    You can't use the Sum() aggregate function on a string field.

    There are 2 things you can do

    • Redefine your existing column item in your db (or schema) to be a numeric field.(recommended)
    • do a System.Int32 conversion on the data you're passing to the aggregate function. so you could do the following

    dtGroupedBy.Compute("sum(CONVERT(" + POWER + ",'System.Int32'))",dvv.RowFilter);

提交回复
热议问题