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 8084393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:46:59+00:00 2026-06-05T17:46:59+00:00

I have a subroutine to insert a record to sql server table. The code:

  • 0

I have a subroutine to insert a record to sql server table.
The code:

    public void Insert_Met(int Counts, char Gender)
    {
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@Counts", Counts);
        parameters.Add("@Gender", Gender);
        // run a stored procedure ExecuteNonQuery
    }

I other line code,

      int counts = Convert.ToInt32(numberUpdowncontrol1.Text);
       // from a control, maybe empty then it is null.
      Insert_Met(counts,'M');

My question is sometimes Counts can be null, so how to change my code?

Thanks,

  • 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. Editorial Team
    Editorial Team
    2026-06-05T17:47:01+00:00Added an answer on June 5, 2026 at 5:47 pm

    You could use int? counts instead of int counts, and check the value within your method:

    public void InsertMet(int? counts, char gender)
    {
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("@Counts", counts.HasValue ? counts.Value : (object)DBNull.Value);
        parameters.Add("@Gender", gender);
        // run a stored procedure ExecuteNonQuery
    }
    

    it is a numericupdown control in windows form. I feel that it is hard to assign a text to an int variable. How to change it?

    In order to set the count value appropriately for the above, you could do:

    int value = (int)numberUpdowncontrol1.Value;
    int? counts = !string.IsNullOrEmpty(numberUpdowncontrol1.Text) ? value : (int?)null;
    
    InsertMet(counts, 'M');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi folks i have a subroutine called CheckDate() in the code behind. How would
I have code that calls an ENTRY in a SUBROUTINE before the SUBROUTINE .
I have a subroutine called debug I use in my code. It basically allows
I have this subroutine setup to connect to a MS Access database: Public Sub
I have a class with a subroutine as follows: Public Sub SetPermissions() If IsNothing(HttpContext.Current.Session)
Let's say I have a subroutine/method that a user can call to test some
I am brand new to CUDA programming. I have a CUDA subroutine that, hopefully,
I have an integer variable that is declared at the head of my subroutine.
have a php code like this,going to convert it in to C#. function isValid($n){
Here is what I have as VBScript Subroutine: sub buildChildAdminStringHierarchical(byval pAdminID, byref adminString) set

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.