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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:43:17+00:00 2026-05-23T18:43:17+00:00

Datatable dtProduto; (Filled) int cdProduto = Convert.ToInt16(dtProduto.Rows[0][cdProduto]); int cdReferencia = Convert.ToInt16(dtProduto.Rows[0][cdReferencia]); The syntax dtProduto.Rows[i][Column]

  • 0

Datatable dtProduto; (Filled)

int cdProduto = Convert.ToInt16(dtProduto.Rows[0]["cdProduto"]);
int cdReferencia = Convert.ToInt16(dtProduto.Rows[0]["cdReferencia"]);

The syntax dtProduto.Rows[i][Column] always returns an object, which one is the best way to convert’em to integers?

Regards, Jorge.

  • 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-23T18:43:17+00:00Added an answer on May 23, 2026 at 6:43 pm

    You’re currently converting them to what would be a “short” — or a 16-bit integer. I don’t think there’s anything wrong with the way you’re doing it now. Simply substitute Convert.ToInt32() if you need a 32-bit Integer instead.

    If you aren’t sure what may be contained in your data source, you might want to be more careful about directly converting your source record data to concrete values by checking for nulls and/or parsing the result. Something like:

    int value;
    if (dtProduto.Rows[0]["cdProduto"] != null)
    {
        if (!int.TryParse(dtProduto.Rows[0]["cdProduto"].ToString(), out value))
        {
            // Log exception, throw exception, do nothing, etc.
        } // else row value is now an integer stored in the value variable
    }
    

    Substitute short for int if you do want 16-bit integers.

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

Sidebar

Related Questions

I have a DataTable which has a column amount for each rows and I'd
I have a DataTable object. Every column is of type string. Using LINQ, how
I have a datatable which is filled from the resultset of a 1 row
I have a DataTable. I want to get every rows first column value and
$(#dataTable tbody).on(click, tr, function(event){ alert($(this).text()); }); is this syntax is for tr's which are
In a .NET Datatable, the columns are Object types, which can include a datatable
Datatable filter is not able apply for Datatable which is stored in session. Can
Primefaces Datatable let you configure the filtering type you use for a column, using
I am assigning a datatable with multiple columns and zero rows to WPF data-grid.
I have a DataTable which is generated from .xls table. I would like to

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.