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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:58:25+00:00 2026-05-27T22:58:25+00:00

Q: The following code: var dtInstTotal = dtExternal.AsEnumerable() .Union(dtEmployed.AsEnumerable()) .OrderBy(d => d.Field<string>(emp_name)); dtInst =

  • 0

Q:

The following code:

        var dtInstTotal = dtExternal.AsEnumerable()
                    .Union(dtEmployed.AsEnumerable())
                    .OrderBy(d => d.Field<string>("emp_name"));

        dtInst = dtInstTotal.CopyToDataTable();//exception

throw an exception:

Value was either too large or too small for an Int16.Couldn’t store
<103930> in emp_num Column. Expected type is Int16. —>
System.OverflowException: Value was either too large or too small for
an Int16.

  • 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-27T22:58:26+00:00Added an answer on May 27, 2026 at 10:58 pm

    I suspect that dtExternal has a short type for emp_num, whereas dtEmployed has some other type (int, long or maybe just ushort) – or maybe vice versa. CopyToDataTable just uses the types from the first table containing the first row it sees, and then it’s having problems when it comes across a value for a column with the same name from a different table. From the docs:

    The schema of the destination table is based on the schema of the first DataRow row in the source sequence. The table metadata is extracted from the DataRow metadata and the table values from the column values of the DataRow.

    Basically: make sure your two original tables have the same schema.

    EDIT: We don’t know what your methods to populate the two original DataTables look like – but you may find that by creating the DataTable first, explicitly setting the type of emp_num, and then filling the table, that will be okay.

    You could even leave your original methods alone, and build a new DataTable with the right schema, then call

    dtInstTotal.CopyToDataTable(tableWithCorrectSchema, LoadOption.PreserveChanges);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code: var constant = Expression.Constant(find me, typeof(string)); // memberExpression evaluates to a
in the following code : var benq:Base64Encoder = new Base64Encoder(); benq.encode(force,0,5); var tmp:String =
If I have the following code: var value : String = StringUtil.substitute(The value {0}
I have the following code: var string = word1;word2;word3,word4,word5,word6.word7; function ends_with(string, character) { var
I have the following code: var items = new List<string> {1, 2, 3}; //
The following code: var m: Map[String, Int] = Map(A -> 1, BB -> 2,
I have the following code: var redirectIp = string.Format({0}{1}, Session[CurrentHost], ip.PathAndQuery); return new RedirectResult(redirectIp);
The following code: var dynamicQuery = from a in _context.Users select a; string[] args
I have the following code: var foo = (from data in pivotedData.AsEnumerable() select new
I have the following code: var bool:String = true; Without an if block or

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.