I've read many of similar questions and tried several different things, but I do not understand why this is not working. The column that is being summed is of the int type. I have tried casting to uint and int32. I appreciate direction. Thank you.
int i = 1;
int total=0;
while (i < 7)
{
string conString = @"Data Source=UATDB2\sqleuat;Initial Catalog=CVNee;User ID=appuser;Integrated Security=true";
SqlConnection connection = new SqlConnection(conString);
connection.Open();
SqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "SELECT SUM(AMOUNT) FROM TRANSACTIONS_DETAIL2 WHERE TRANSACTIONS_DETAIL2.TRANS_TYPE =" + i + "AND TRANSACTIONS_DETAIL2.HOH_UPI = '185292000'";
int amt = ((int)cmd.ExecuteScalar());
//amt = cmd.ExecuteScalar();
if (i == 1)
{
total = total + amt;
}
if (i == 2)
{
total = total - amt;
}
if (i == 3)
{
total = total - amt;
}
if (i == 4)
{
total = total + amt;
}
if (i == 5)
{
total = total + amt;
}
if (i == 6)
{
total = total + amt;
}
connection.Close();
ViewBag.TotalBalance = total;
i++;
}