I am working with someone else's code and I'm not good with C# at all!
I need to multiply total1
and total2
. The code below gives me answer = 0
and that's not right. What is wrong here?! Also, the value of total1
is saved in a MS SQL database as an int if that matters. When I put in a breakpoint on the last line I notice it's reading total2
as 9
and total1
as "15"
(with the quotes).
System.Data.OleDb.OleDbConnection pcn;
System.Data.OleDb.OleDbCommand pcm;
System.Data.OleDb.OleDbDataReader prs;
pcn = new System.Data.OleDb.OleDbConnection("");
pcm = new System.Data.OleDb.OleDbCommand();
pcn.Open();
pcm.Connection = pcn;
var tableSql = String.Format(@"select sum(TicSold) as total1 from BusTickets where TicketType = '9'");
pcm.CommandText = tableSql;
prs = pcm.ExecuteReader();
var rowcount = 0;
while (prs.Read())
{
rowcount++;
total1 = prs["total1"].ToString();
}
prs.Close();
pcn.Close();
int total2 = 9;
int answer = total2 * Convert.ToInt32(total1);
UPDATE: I was able to get answer to show the correct number rather than 0 by using Justin's method below, but now I want to show "answer" on the .aspx page. Previously, I would make it public (public int answer) and then in my html put <%= answer %> for the amount to show. But it still shows 0. The code above is my code behind, the code below is my main page. Again, sorry for the lack of knowledge on this, I'm learning.
Total Ticket Profit: <strong><%= answer %></strong></p>
</div>