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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:12:42+00:00 2026-05-28T02:12:42+00:00

Having a spot of trouble with the following code. The method NextIPID() should simply

  • 0

Having a spot of trouble with the following code. The method NextIPID() should simply look to a table in SQL Server, which returns the Max Value of field IPID, and then adds 1 to it, to get the next number in the sequence.

public int NextIPID()
    {
        string strConnect = BuildConnectionString();
        SqlConnection linkToDB = new SqlConnection(strConnect);
        linkToDB.Open();
        string sqlStat = "SELECT MAX(IPID) FROM tblInterestedParties;";
        SqlCommand sqlCom = new SqlCommand(sqlStat, linkToDB);   
        int intNextIPID = (Int32)sqlCom.ExecuteScalar();
        linkToDB.Close();
        return intNextIPID + 1;                             
    }

However I keep getting the error message

“When casting from a number, the value must be a number less than infinity”.

I suspect this is because the table is currently empty, but then I expected the Execute Scalar to return ‘0’ and hence adding one to this would mean the method returns the next value i.e. 1. However this is not happening.

Assistance greatly appreciated.

  • 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-05-28T02:12:43+00:00Added an answer on May 28, 2026 at 2:12 am

    If the table is empty, your query won’t return 0, it will return NULL. What you could use is

    SELECT ISNULL((SELECT MAX(IPID) FROM tblInterestedParties), 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some trouble creating a nested association and I can't quite spot
I'm having trouble parsing the following link. I'd like to be able to extract
I'm having a spot of trouble in making my functions work and my book
I'm having trouble figuring out my last section of code for a Dynamic Coin
I'm having trouble with ranking the records in my table. It seems to be
Following on from this answer , I am having a spot of bother with
I'm having a spot of trouble with ASP.NET 4.0 memberships. I want to have
i am having trouble getting this to work, can any one spot the issue?
I'm having a spot of trouble with generics in C#. I have to store
I have the following php code, which has been snipped for brevity. I am

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.