1

SQLサーバーにデータベースがあります。私が質問しなければならないテーブルは次のとおりです:それは4つの列を持っています:(テーブル名:投票)

idbigintnotnull主キー
optAvotesbigintnotnull optBvotes bigint notnull
optCvotes bigint 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は結果を連結文字列として表示します。したがって、できるだけ早く解決策を教えてください。 。

4

1 に答える 1

0

Totalは整数であり、文字列を受け入れません。A、B、Cを文字列から整数に変換してから追加し、整数の結果をTotalに割り当てる必要があります。

試す :

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

また

Total = CInt(A) + CInt(B) + CInt(C)
于 2013-03-29T14:35:21.957 に答える