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. returning null value from procedure

returning null value from procedure

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasesql-serversysadmin
4 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.net2.0 with c# with sql server 2000 when iam executing the procedure in local system it is working fine.but when iam executing in client system procedure returns null value, i have checked all connection string , and session value all are working can you correct the code which helps me

        SqlConnection concreate = new SqlConnection(strcon);
    
        string pp = "";
        pp = "create procedure getsum( @BranchKey int,@FromDate smalldatetime,@ToDate smalldatetime, @tot decimal output )";
        pp += "as";
        pp += "\\n";
        pp += "set @tot=(SELECT  SUM(Amount) FROM   AllTransactions WHERE BranchKey=@BranchKey  and  (TransCode <> 0) and (TransDate > @FromDate) and (TransDate < @ToDate)  GROUP by  BranchKey)";
        pp += "return @tot";
        pp += ";";
    
        
        SqlCommand cmdcreate = new SqlCommand(pp, concreate);
        concreate.Open();
        cmdcreate.ExecuteNonQuery();
        concreate.Close();
    
        SqlConnection conproc = new SqlConnection(strcon);
        conproc.Open();
        SqlCommand cmdproc = new SqlCommand("getsum", conproc);
        cmdproc.CommandType = CommandType.StoredProcedure;
    
    
        cmdproc.Parameters.AddWithValue("@BranchKey", Convert.ToInt32(Session\["BranchKey"\]));
        DateTime dt = Convert.ToDateTime(txtfrom.Text.ToString());
        string fromDate = dt.ToShortDateString();
        DateTime dt1 = Convert.ToDateTime(txtto.Text.ToString());
        string toDate = dt1.ToShortDateString();
        cmdproc.Parameters.AddWithValue("@FromDate", fromDate);
        cmdproc.Parameters.AddWithValue("@ToDate", toDate);
    
        SqlParameter p1 = cmdproc.Parameters.Add("@tot", SqlDbType.Decimal);
        p1.Direction = ParameterDirection.Output;
        if ((cmdproc.ExecuteScalar() != DBNull.Value) && (cmdproc.Parameters\["@tot"\].Value) != DBNull.Value)
        {
            decimal ot = Convert.ToDecimal(cmdproc.Parameters\["@tot"\].Value);
            if (ot != null)
            {
                txttotal.Text = ot.ToString();
                conproc.Close();
            }
        }
        else
        {
    
    
            clsdataset.ShowAlertMessage("No Data");
    
        }
    
    T S T 3 Replies Last reply
    0
    • D developerit

      hi iam using asp.net2.0 with c# with sql server 2000 when iam executing the procedure in local system it is working fine.but when iam executing in client system procedure returns null value, i have checked all connection string , and session value all are working can you correct the code which helps me

          SqlConnection concreate = new SqlConnection(strcon);
      
          string pp = "";
          pp = "create procedure getsum( @BranchKey int,@FromDate smalldatetime,@ToDate smalldatetime, @tot decimal output )";
          pp += "as";
          pp += "\\n";
          pp += "set @tot=(SELECT  SUM(Amount) FROM   AllTransactions WHERE BranchKey=@BranchKey  and  (TransCode <> 0) and (TransDate > @FromDate) and (TransDate < @ToDate)  GROUP by  BranchKey)";
          pp += "return @tot";
          pp += ";";
      
          
          SqlCommand cmdcreate = new SqlCommand(pp, concreate);
          concreate.Open();
          cmdcreate.ExecuteNonQuery();
          concreate.Close();
      
          SqlConnection conproc = new SqlConnection(strcon);
          conproc.Open();
          SqlCommand cmdproc = new SqlCommand("getsum", conproc);
          cmdproc.CommandType = CommandType.StoredProcedure;
      
      
          cmdproc.Parameters.AddWithValue("@BranchKey", Convert.ToInt32(Session\["BranchKey"\]));
          DateTime dt = Convert.ToDateTime(txtfrom.Text.ToString());
          string fromDate = dt.ToShortDateString();
          DateTime dt1 = Convert.ToDateTime(txtto.Text.ToString());
          string toDate = dt1.ToShortDateString();
          cmdproc.Parameters.AddWithValue("@FromDate", fromDate);
          cmdproc.Parameters.AddWithValue("@ToDate", toDate);
      
          SqlParameter p1 = cmdproc.Parameters.Add("@tot", SqlDbType.Decimal);
          p1.Direction = ParameterDirection.Output;
          if ((cmdproc.ExecuteScalar() != DBNull.Value) && (cmdproc.Parameters\["@tot"\].Value) != DBNull.Value)
          {
              decimal ot = Convert.ToDecimal(cmdproc.Parameters\["@tot"\].Value);
              if (ot != null)
              {
                  txttotal.Text = ot.ToString();
                  conproc.Close();
              }
          }
          else
          {
      
      
              clsdataset.ShowAlertMessage("No Data");
      
          }
      
      T Offline
      T Offline
      Tej Aj
      wrote on last edited by
      #2

      check this post http://opexsolution.com/forum/viewtopic.php?f=15&t=55&p=169#p169[^]

      1 Reply Last reply
      0
      • D developerit

        hi iam using asp.net2.0 with c# with sql server 2000 when iam executing the procedure in local system it is working fine.but when iam executing in client system procedure returns null value, i have checked all connection string , and session value all are working can you correct the code which helps me

            SqlConnection concreate = new SqlConnection(strcon);
        
            string pp = "";
            pp = "create procedure getsum( @BranchKey int,@FromDate smalldatetime,@ToDate smalldatetime, @tot decimal output )";
            pp += "as";
            pp += "\\n";
            pp += "set @tot=(SELECT  SUM(Amount) FROM   AllTransactions WHERE BranchKey=@BranchKey  and  (TransCode <> 0) and (TransDate > @FromDate) and (TransDate < @ToDate)  GROUP by  BranchKey)";
            pp += "return @tot";
            pp += ";";
        
            
            SqlCommand cmdcreate = new SqlCommand(pp, concreate);
            concreate.Open();
            cmdcreate.ExecuteNonQuery();
            concreate.Close();
        
            SqlConnection conproc = new SqlConnection(strcon);
            conproc.Open();
            SqlCommand cmdproc = new SqlCommand("getsum", conproc);
            cmdproc.CommandType = CommandType.StoredProcedure;
        
        
            cmdproc.Parameters.AddWithValue("@BranchKey", Convert.ToInt32(Session\["BranchKey"\]));
            DateTime dt = Convert.ToDateTime(txtfrom.Text.ToString());
            string fromDate = dt.ToShortDateString();
            DateTime dt1 = Convert.ToDateTime(txtto.Text.ToString());
            string toDate = dt1.ToShortDateString();
            cmdproc.Parameters.AddWithValue("@FromDate", fromDate);
            cmdproc.Parameters.AddWithValue("@ToDate", toDate);
        
            SqlParameter p1 = cmdproc.Parameters.Add("@tot", SqlDbType.Decimal);
            p1.Direction = ParameterDirection.Output;
            if ((cmdproc.ExecuteScalar() != DBNull.Value) && (cmdproc.Parameters\["@tot"\].Value) != DBNull.Value)
            {
                decimal ot = Convert.ToDecimal(cmdproc.Parameters\["@tot"\].Value);
                if (ot != null)
                {
                    txttotal.Text = ot.ToString();
                    conproc.Close();
                }
            }
            else
            {
        
        
                clsdataset.ShowAlertMessage("No Data");
        
            }
        
        S Offline
        S Offline
        shreekar
        wrote on last edited by
        #3

        Not an answer, but a question - Why are you creating the SP in your code? Shreekar

        1 Reply Last reply
        0
        • D developerit

          hi iam using asp.net2.0 with c# with sql server 2000 when iam executing the procedure in local system it is working fine.but when iam executing in client system procedure returns null value, i have checked all connection string , and session value all are working can you correct the code which helps me

              SqlConnection concreate = new SqlConnection(strcon);
          
              string pp = "";
              pp = "create procedure getsum( @BranchKey int,@FromDate smalldatetime,@ToDate smalldatetime, @tot decimal output )";
              pp += "as";
              pp += "\\n";
              pp += "set @tot=(SELECT  SUM(Amount) FROM   AllTransactions WHERE BranchKey=@BranchKey  and  (TransCode <> 0) and (TransDate > @FromDate) and (TransDate < @ToDate)  GROUP by  BranchKey)";
              pp += "return @tot";
              pp += ";";
          
              
              SqlCommand cmdcreate = new SqlCommand(pp, concreate);
              concreate.Open();
              cmdcreate.ExecuteNonQuery();
              concreate.Close();
          
              SqlConnection conproc = new SqlConnection(strcon);
              conproc.Open();
              SqlCommand cmdproc = new SqlCommand("getsum", conproc);
              cmdproc.CommandType = CommandType.StoredProcedure;
          
          
              cmdproc.Parameters.AddWithValue("@BranchKey", Convert.ToInt32(Session\["BranchKey"\]));
              DateTime dt = Convert.ToDateTime(txtfrom.Text.ToString());
              string fromDate = dt.ToShortDateString();
              DateTime dt1 = Convert.ToDateTime(txtto.Text.ToString());
              string toDate = dt1.ToShortDateString();
              cmdproc.Parameters.AddWithValue("@FromDate", fromDate);
              cmdproc.Parameters.AddWithValue("@ToDate", toDate);
          
              SqlParameter p1 = cmdproc.Parameters.Add("@tot", SqlDbType.Decimal);
              p1.Direction = ParameterDirection.Output;
              if ((cmdproc.ExecuteScalar() != DBNull.Value) && (cmdproc.Parameters\["@tot"\].Value) != DBNull.Value)
              {
                  decimal ot = Convert.ToDecimal(cmdproc.Parameters\["@tot"\].Value);
                  if (ot != null)
                  {
                      txttotal.Text = ot.ToString();
                      conproc.Close();
                  }
              }
              else
              {
          
          
                  clsdataset.ShowAlertMessage("No Data");
          
              }
          
          T Offline
          T Offline
          T M Gray
          wrote on last edited by
          #4

          Is the data the same in the two systems? Are you sure the query returns anything? From the documentation for ExecuteScalar: The first column of the first row in the result set, or a null reference (Nothing in Visual Basic) if the result set is empty. You could try getting rid of the output parameter and just using a SELECT instead of a SET and RETURN. Also, look into @ strings rather than lots of concatenation.

          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