charan sekhar

charan sekhar

  • NA
  • 108
  • 0

querry is returning zero eventhough data is present in data base

Jun 15 2010 9:40 AM
 
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

Answers (5)