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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:56:24+00:00 2026-05-30T16:56:24+00:00

I am having difficulties with this code where I’m trying to put a certain

  • 0

I am having difficulties with this code where I’m trying to put a certain conversion for a long from data out of a dataset.

I’m trying to check if it’s possible to convert the value inside that position in the dataset. If it doesn’t work, it means that there are no items in the dataset, because all the other entrants (readed from a txtfile) are valid

Code:

long Recid = 0;
Boolean checkrecid = long.TryParse(dts.Tables[0].Rows[0]["RECID"], out Recid)

Errors:

The best overloaded method match for 'long.TryParse(string, out long)' has some invalid arguments and
Argument 1: cannot convert from 'object' to 'string'    

Thanks in advance.

  • 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-30T16:56:25+00:00Added an answer on May 30, 2026 at 4:56 pm

    Two options:

    If your data is a string, then cast it as a string

    long Recid = 0;
    Boolean checkrecid = long.TryParse((string)dts.Tables[0].Rows[0]["RECID"], out Recid)
    

    otherwise, call .ToString() on it

    long Recid = 0;
    Boolean checkrecid = long.TryParse(dts.Tables[0].Rows[0]["RECID"].ToString(), out Recid)
    

    The reason you need to do this is because the long.TryParse() method only accepts an instance of a string as its first parameter http://msdn.microsoft.com/en-us/library/zc2x2b1h.aspx

    The data coming out of your dataset is typed as an object and therefore the Int64.TryParse() method can’t be sure if it is a string and it is failing. (In general, programming does not allow for ambiguity and that is why the TryParse method doesn’t attempt to convert it for you – you must be explicit about what it is you want and what you provide).

    Datasets are very flexible because you can store any object in them, but its more work for the programmer to cast the type back after getting it back out again. Other alternatives, like strongly-typed datasets, get around that problem by being more rigid about what types you can store in them, but then you don’t have to keep casting things all the time.

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

Sidebar

Related Questions

I am having difficulties with forms, specifically ModelMultipleChoiceField. I've pieced together this code from
I'm having some difficulties with passing functions around. I have this code: var options
im having difficulties figuring this out, ive looked at examples here and on the
I'm having some difficulties to starting a background process in Ruby. I've this code
I'm having some difficulties with Ajax.BeginForm I have something like this in a view
I am having difficulties when trying to insert files into a SQL Server database.
I'm having some difficulties with this problem. The main idea is, I initialized a
I'm having difficulties adding momentum to my spinning wheel. I have this wheel (something
I am having difficulties w/ writing and reading an array of objects from a
I have having difficulties on this one page login.php. Because of the nature of

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.