Dataset 对使用sql server数据库中的数据集读取的数据执行数学运算

Dataset 对使用sql server数据库中的数据集读取的数据执行数学运算,dataset,Dataset,我在sql server上有一个数据库。我要提问的表格如下: 它有4列:表名:投票 id bigint notnull主键 OPTABIGINT notnull OPTBBIGINT notnull OPTCBIGINT notnull 我想对这些列值执行数学运算,如加法、百分比计算等。我是这样做的: dim da as new sqldataadapter("select * from votes",con) dim ds as new dataset da.fill(ds) dim A,B,

我在sql server上有一个数据库。我要提问的表格如下: 它有4列:表名:投票

id bigint notnull主键 OPTABIGINT notnull OPTBBIGINT notnull OPTCBIGINT notnull 我想对这些列值执行数学运算,如加法、百分比计算等。我是这样做的:

dim da as new sqldataadapter("select * from votes",con)
dim ds as new dataset
da.fill(ds)
dim A,B,C,Total as integer
A=ds.tables(0).rows(0).item("optAvotes").tostring
B=ds.tables(0).rows(0).item("optBvotes").tostring
C=ds.tables(0).rows(0).item("optCvotes").tostring
Total=A+B+C
当我显示Total的值时,它显示一个从字符串转换而来的错误
然而,若我将这些变量声明为字符串,那个么Total=A+B+C将结果显示为一个连接的字符串。因此,请尽快告诉我解决方案。

总计是一个整数,不接受字符串。您需要将A、B、C从字符串转换为整数,然后再添加它们并将整数结果分配给Total

尝试:

Total = Convert.ToInt32(A) + Convert.ToInt32(B) + Convert.ToInt32(C)
Total = CInt(A) + CInt(B) + CInt(C)