Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. getting value zero when caculating value between dates in ado.net using asp.net with c#

getting value zero when caculating value between dates in ado.net using asp.net with c#

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabase
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    developerit
    wrote on last edited by
    #1

    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();

    B T T 3 Replies Last reply
    0
    • D developerit

      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();

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • B Blue_Boy

        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

        D Offline
        D Offline
        developerit
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • D developerit

          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();

          T Offline
          T Offline
          Tash18
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • D developerit

            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();

            T Offline
            T Offline
            Tej Aj
            wrote on last edited by
            #5

            check this post http://opexsolution.com/forum/viewtopic.php?f=15&t=54&p=155#p155[^]

            D 1 Reply Last reply
            0
            • T Tash18

              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

              D Offline
              D Offline
              developerit
              wrote on last edited by
              #6

              i have debug and absorb that text box field is taking date in mm/dd/yyyy format

              T 1 Reply Last reply
              0
              • T Tej Aj

                check this post http://opexsolution.com/forum/viewtopic.php?f=15&t=54&p=155#p155[^]

                D Offline
                D Offline
                developerit
                wrote on last edited by
                #7

                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

                T 1 Reply Last reply
                0
                • D developerit

                  i have debug and absorb that text box field is taking date in mm/dd/yyyy format

                  T Offline
                  T Offline
                  Tash18
                  wrote on last edited by
                  #8

                  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

                  D 1 Reply Last reply
                  0
                  • T Tash18

                    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

                    D Offline
                    D Offline
                    developerit
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • D developerit

                      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

                      T Offline
                      T Offline
                      Tej Aj
                      wrote on last edited by
                      #10

                      check this post http://opexsolution.com/forum/viewtopic.php?f=15&t=54&start=10[^]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups