SqlConnection con = new SqlConnection(strcon); DateTime dt = Convert.ToDateTime(txtfrom.Text); string fromDate = dt.ToShortDateString(); DateTime dt1 = Convert.ToDateTime(txtto.Text); string toDate = dt1.ToShortDateString(); SqlCommand cmdallltransactions = new SqlCommand("select sum(Amount) from AllTransactions where (TransCode <> 0) and (BranchKey = @BranchKey) and ((TransDate > @FromDate )and (TransDate < @ToDate)) GROUP by BranchKey", con); cmdallltransactions.CommandType = CommandType.Text; cmdallltransactions.Parameters.Add(new SqlParameter("@BranchKey", Convert.ToInt32(Session["BranchKey"]))); cmdallltransactions.Parameters.Add(new SqlParameter("@FromDate", fromDate)); cmdallltransactions.Parameters.Add(new SqlParameter("@ToDate",toDate)); con.Open(); decimal tot = 0; tot = Convert.ToDecimal(cmdallltransactions.ExecuteScalar()); txttotal.Text = tot.ToString(); con.Close();
|
the querry is working fine in sql but returning zero in asp.net can you correct my code which helps me
Sam HobbsPosted Jun 21, 2010, 3:14 AM
If it were me, I would determine what is returnd by cmdallltransactions.ExecuteScalar()). When you have multiple things being done in one line, it helps to split things up so you can determine what is happening.
Also, I don't see the code using a try/catch blcok. Before asking for help in a forum, try using a try/catch block to catch problems whenever the code you need help with that can result in an exception being thrown.
charan sekharPosted Jun 21, 2010, 2:05 AM
iam performing execute operation also you can seee
tot = Convert.ToDecimal(cmdallltransactions.ExecuteScalar());
txttotal.Text = tot.ToString();
con.Close();
Sam HobbsPosted Jun 20, 2010, 5:53 AM
charan sekharPosted Jun 19, 2010, 8:02 AM
PJ MartinsPosted Jun 17, 2010, 11:31 AM
((TransDate >= @FromDate )and (TransDate <= @ToDate))
or
(TransDate between @FromDate and @ToDate)