Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 53945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:08:34+00:00 2026-05-10T17:08:34+00:00

I have an asp.net text form that contains numerous decimal fields that are optional.

  • 0

I have an asp.net text form that contains numerous decimal fields that are optional. I want to selectively update the database but not inserting a ‘0’ for fields that do not have data (maintaining the null status).

Typically, I would create multiple functions, each with a different signature to handle this. However, I am inserting the data through a webservice which does not allow a function with the same name to have multiple signatures. I can think of a couple ways to work around this, but none ‘pragmatically’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:08:35+00:00Added an answer on May 10, 2026 at 5:08 pm

    Nullable Types are meant for the same purpose. They represent value types with the possibility of having no data in them. Presence of value can be checked using HasValue property of these types.

    Pseudo code to read the fields:

    decimal? dValue; // default value is null  if(decimalValueExists) {   dValue = <value read from text file> }  

    When you say multiple methods – I assume these are overloaded methods to be able to add optional fields (so n optional fields means n more methods)

    You can avoid writing those methods by writing single method. Suppose you have one required field and one optional field:

    public class MyFields {     decimal  req1;     decimal? opt1; // optional field 1   } 

    Then define the web service method to use it:

    [WebMethod] void MyWSMethod(MyFields myFields) {/* code here will ultimately call InsertMyFields */}  void InsertMyFields(MyFields myFields) {     using (SqlConnection connection = new SqlConnection(connectionString))     {         // Create the command and set its properties.         SqlCommand command = new SqlCommand();         command.Connection = connection;         command.CommandText = 'AddMyFields';         command.CommandType = CommandType.StoredProcedure;          // Add the required input parameter         SqlParameter parameter1 = new SqlParameter();         parameter1.ParameterName = '@ReqField1';         parameter1.SqlDbType = SqlDbType.NVarChar;         parameter1.Direction = ParameterDirection.Input;         parameter1.Value = myFields.req1;          // Add the parameter to the Parameters collection.          command.Parameters.Add(parameter1);          // Add the optional parameter and set its properties.         SqlParameter parameter2 = new SqlParameter();         parameter2.ParameterName = '@OptField1';         parameter2.SqlDbType = SqlDbType.NVarChar;         parameter2.Direction = ParameterDirection.Input;         parameter2.Value = myFields.opt1 ?? DBNull.Value; //null coalescing operator          // Add the parameter to the Parameters collection.          command.Parameters.Add(parameter2);          //.. rest of the code     }  }  

    If the nullable type has a value, Null Coalescing Operator will set the value or else it will set the other value that you specify (DBNull.Value in our case).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The idea of Markus Lux can be also applied with… May 11, 2026 at 3:57 pm
  • added an answer fwrite((const void*)val,sizeof(int),1,fp); should be: fwrite((const void*) & val,sizeof(int),1,fp); BTW, if… May 11, 2026 at 3:57 pm
  • added an answer Pick a standard schema, such as core, cosine, inetOrgPerson, eduPerson,… May 11, 2026 at 3:57 pm

Related Questions

Im working on an ASP.Net app with c#. I am stuck on a problem
I have a working login form in an asp.net application. Standard stuff with a
I'm trying to add a script reference to jQuery in my master page so
I'm working on a sort of a CMS/Wiki application to help me experiment with

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.