整数を合計して結果をTextBox
にC#で表示するときに問題が発生しました。コードを実行すると、その結果はlim30den50tot
という結果になります。私はlim30den50tot
、lim60den50tot
などを合計したいと思います。どうすればいいですか?C#を使用して整数を合計してテキストボックスに結果を表示
private int lim30den50tot;
private int lim60den50tot;
private int lim150den50tot;
private int lim450den50tot;
private int lim600den50tot;
private void JumlahLembar()
{
int lim30 = 0;
int lim60 = 0;
int lim150 = 0;
int lim450 = 0;
int lim600 = 0;
foreach(DataGridViewRow row in JadwalisiGV.Rows)
{
if (!row.IsNewRow)
{
OleDbConnection kon = new OleDbConnection(koneksi);
OleDbCommand command = kon.CreateCommand();
kon.Open();
command.CommandText = "select * from [StokLembar$] where [Limit] = " + row.Cells["Limit"].Value;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int den50 = int.Parse(reader["Lembar Denom 50"].ToString());
int den100 = int.Parse(reader["Lembar Denom 100"].ToString());
if (row.Cells["Limit"].Value.ToString() == "30")
{
lim30++;
lim30den50tot = lim30 * 2 * den50 * 50000;
}
else if (row.Cells["Limit"].Value.ToString() == "60")
{
lim60++;
lim60den50tot = lim60 * 2 * den50 * 50000;
}
else if (row.Cells["Limit"].Value.ToString() == "150")
{
lim150++;
lim150den50tot = lim150 * 2 * den50 * 50000;
}
else if (row.Cells["Limit"].Value.ToString() == "450")
{
lim450++;
lim450den50tot = lim450 * 2 * den50 * 50000;
}
else if (row.Cells["Limit"].Value.ToString() == "600")
{
lim600++;
lim600den50tot = lim600 * 2 * den50 * 50000;
}
TotalDen50Box.Text = (lim30den50tot + lim600den50tot + lim150den50tot + lim450den50tot + lim600den50tot).ToString();
}
kon.Close();
}
}
}
あなたの答えをありがとう。できます :) –