SQLサーバーデータベースに列タイプmoneyがあります。これはmoneyAcumulated
です。次に、command
オブジェクトを使用して、列の値をもたらすストアプロシージャを実行しますmoneyAcumulated
。次に、whileループで、ストアドプロシージャが返す各列のすべての値を変数に格納します。
SqlCommand command = new SqlCommand("getTickets", Connection.getConnection());
command.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = command.ExecuteReader();
string bet = "";
decimal moneyAcumulated = 0.0M;
string id= "";
string name = "";
int cod = -1;
decimal prize = 0.0M;
while (reader.Read())
{
bet = reader.GetString(0);
moneyAcumulated = reader.GetDecimal(1); // This variable doesn't chage its value
name = reader.GetString(2);
id = reader.GetString(3);
cod = reader.GetInt32(4);
}
最初にwhileループが繰り返されると、各変数は正しい値を取ります(これには、が含まmoneyAcumulated
れますがreader
、2回目moneyAcumulated
はその値が変更されず、他の変数は変更されます。なぜですか?