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

Related Questions

I have a ASP.Net web form that contains both text box fields and hidden
I have an ASP.NET user control that contains a text box control and a
I have an ASP.NET page that contains a form and a button. In order
I have the following problem in ASP.NET: there is a form that contains a
I have an ASP.NET form with three text inputs, one each for Work Phone,
I have a simple in VB/ASP.NET form containing two text boxes, I am attempting
Using ASP.NET VB, I have a form with some text boxes and a Gridview.
I have an ASP.Net Application that sends text messages to mobile phones. It does
I have an asp.net TextBox in which I want to check if the text
I have an HTML form that calls an ASP.NET page when a button is

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.