Click here to Skip to main content
15,884,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Iam Using asp.net3.5 with c#

in my web service i want to give the default value for "onDeliveryAmount" , how to give can you help me please

below is my webmethod

C#
[WebMethod(Description = "Creates A new entry in a DataBase")]



   public string  NewItem(string AdreseeEmail, string senderEmail, string phoneNum, string boxMachineName,  decimal onDeliveryAmount)
   {
       SqlConnection MyConnection = new SqlConnection(StrConnection);
       SqlCommand MyCommand = new SqlCommand("ProCreateDelivery", MyConnection);

       MyCommand.CommandType = CommandType.StoredProcedure;
       MyCommand.Parameters.AddWithValue("@adreseeEmail",AdreseeEmail);
       MyCommand.Parameters.AddWithValue("@senderEmail",senderEmail);
       MyCommand.Parameters.AddWithValue("@phoneNum",phoneNum);
       MyCommand.Parameters.AddWithValue("@boxMachineName",boxMachineName);
       MyCommand.Parameters.AddWithValue("@onDeliveryAmount",onDeliveryAmount);
      try
      {
           MyConnection.Open();

           if (MyCommand.ExecuteNonQuery() != 0)

           {
               strResult = "Created Successfully ..!";
           }
           strResult = " Created Successfully ..!";

       }
      catch(Exception ex)
       {

           strResult = ex.ToString();

      }
       MyConnection.Close();
       return strResult;
   }
Posted
Updated 3-Jul-17 23:36pm
v2
Comments
[no name] 26-Mar-12 7:44am    
Format code snippets
Sushil Mate 26-Mar-12 7:48am    
Default value for what reason? could you explain more, what exactly you want to give default value to onDeliveryAmount.
developerit 26-Mar-12 8:22am    
default value zero i want to give because if user doent gives value then webservice gives me error

C#
[WebMethod(Description = "Creates A new entry in a DataBase")]
     public string  NewItem(string AdreseeEmail, string senderEmail, string phoneNum, string boxMachineName,  decimal onDeliveryAmount)
    {    
        SqlConnection MyConnection = new SqlConnection(StrConnection);
        SqlCommand MyCommand = new SqlCommand("ProCreateDelivery", MyConnection);
 
        MyCommand.CommandType = CommandType.StoredProcedure;
        MyCommand.Parameters.AddWithValue("@adreseeEmail",AdreseeEmail);
        MyCommand.Parameters.AddWithValue("@senderEmail",senderEmail);
        MyCommand.Parameters.AddWithValue("@phoneNum",phoneNum);
        MyCommand.Parameters.AddWithValue("@boxMachineName",boxMachineName);
         if (onDeliveryAmount == null)
            {
                MyCommand.Parameters.AddWithValue("@onDeliveryAmount", 0);
            }
            else
            {
                MyCommand.Parameters.AddWithValue("@onDeliveryAmount", onDeliveryAmount);
            }
       try
       {
            MyConnection.Open();
 
            if (MyCommand.ExecuteNonQuery() != 0)
 
            {
                strResult = "Created Successfully ..!";
            }
            strResult = " Created Successfully ..!";
        
        }
       catch(Exception ex)
        {
 
            strResult = ex.ToString();
       
       }
        MyConnection.Close();
        return strResult;    
    }
 
Share this answer
 
Comments
developerit 27-Mar-12 4:21am    
Thanks for Code Project Team....Really It Helps Me a lot.....
Sushil Mate 27-Mar-12 4:48am    
welcome :)
WebMethod doesn't support default parameters. You could overload the method or if a value is out of range, say 0, check for that and supply the default value within the method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900