getting value zero when caculating value between dates in ado.net using asp.net with c#
-
hi ,iam using asp.net with c# iam trying to return sum of amount between the date values by using the same querry in sql it it working perfect . but when iam using in asp.net with c# ,it is returning zero value .....can you correct my code which helps me
SqlCommand cmdallltransactions = new SqlCommand("SELECT SUM(Amount) FROM AllTransactions WHERE TransDate BETWEEN '"+ txtfrom.Text +"' and'" + txtto.Text + "'and (TransCode <> 0) and BranchKey=" + Convert.ToInt32(Session["BranchKey"]) + "GROUP by BranchKey", con);
con.Open();
txttotal.Text = Convert.ToString(Convert.ToInt64(cmdallltransactions.ExecuteScalar()));
con.Close(); -
hi ,iam using asp.net with c# iam trying to return sum of amount between the date values by using the same querry in sql it it working perfect . but when iam using in asp.net with c# ,it is returning zero value .....can you correct my code which helps me
SqlCommand cmdallltransactions = new SqlCommand("SELECT SUM(Amount) FROM AllTransactions WHERE TransDate BETWEEN '"+ txtfrom.Text +"' and'" + txtto.Text + "'and (TransCode <> 0) and BranchKey=" + Convert.ToInt32(Session["BranchKey"]) + "GROUP by BranchKey", con);
con.Open();
txttotal.Text = Convert.ToString(Convert.ToInt64(cmdallltransactions.ExecuteScalar()));
con.Close();Check if your session return null value or correct value, put space after and before
AND
conditions,GROUP BY
condition :developerit wrote:
SqlCommand cmdallltransactions = new SqlCommand("SELECT SUM(Amount) FROM AllTransactions WHERE TransDate BETWEEN '"+ txtfrom.Text +"' and '" + txtto.Text + "' and (TransCode <> 0) and BranchKey=" + Convert.ToInt32(Session["BranchKey"]) + " GROUP by BranchKey", con);
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
Check if your session return null value or correct value, put space after and before
AND
conditions,GROUP BY
condition :developerit wrote:
SqlCommand cmdallltransactions = new SqlCommand("SELECT SUM(Amount) FROM AllTransactions WHERE TransDate BETWEEN '"+ txtfrom.Text +"' and '" + txtto.Text + "' and (TransCode <> 0) and BranchKey=" + Convert.ToInt32(Session["BranchKey"]) + " GROUP by BranchKey", con);
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
hi, every thing is ok, it is returning session values also,i have checked with break ponts.but at final it is returning zero . even there is already values are present in database it is returning zero. can u correct the code which helps me.
-
hi ,iam using asp.net with c# iam trying to return sum of amount between the date values by using the same querry in sql it it working perfect . but when iam using in asp.net with c# ,it is returning zero value .....can you correct my code which helps me
SqlCommand cmdallltransactions = new SqlCommand("SELECT SUM(Amount) FROM AllTransactions WHERE TransDate BETWEEN '"+ txtfrom.Text +"' and'" + txtto.Text + "'and (TransCode <> 0) and BranchKey=" + Convert.ToInt32(Session["BranchKey"]) + "GROUP by BranchKey", con);
con.Open();
txttotal.Text = Convert.ToString(Convert.ToInt64(cmdallltransactions.ExecuteScalar()));
con.Close(); -
hi ,iam using asp.net with c# iam trying to return sum of amount between the date values by using the same querry in sql it it working perfect . but when iam using in asp.net with c# ,it is returning zero value .....can you correct my code which helps me
SqlCommand cmdallltransactions = new SqlCommand("SELECT SUM(Amount) FROM AllTransactions WHERE TransDate BETWEEN '"+ txtfrom.Text +"' and'" + txtto.Text + "'and (TransCode <> 0) and BranchKey=" + Convert.ToInt32(Session["BranchKey"]) + "GROUP by BranchKey", con);
con.Open();
txttotal.Text = Convert.ToString(Convert.ToInt64(cmdallltransactions.ExecuteScalar()));
con.Close(); -
Hi... I hope the problem is with the date which the query gets from the text field. can u debug and tell me in what format the date is returned from the text field.. Thanks and regards, Tash
i have debug and absorb that text box field is taking date in mm/dd/yyyy format
-
check this post http://opexsolution.com/forum/viewtopic.php?f=15&t=54&p=155#p155[^]
i have check this post also but the result iam getting the same zero. i have checked the connection string,session value every thing is fine i have run the same querry in sql analyzer also it is working fine and result is displayed but in asp.net it is returning zero can give suggestion what to do next
-
i have debug and absorb that text box field is taking date in mm/dd/yyyy format
-
Hi.. Do one thing debug the code, add a 'quick watch' on the query and copy the query from the 'quick watch' window and paste in on sql analyzer and run the query and let me know. Thanks and Regards, Tash
hi, i have done debugging very carefully and copy and paste the querry in sql analyzer but in sql it is returning data . and in asp.net it is returning zero.
-
i have check this post also but the result iam getting the same zero. i have checked the connection string,session value every thing is fine i have run the same querry in sql analyzer also it is working fine and result is displayed but in asp.net it is returning zero can give suggestion what to do next