C# error message when getting a table from an adapter

Posted on 2012-09-07
Last Modified: 2012-09-22
Hey guys!!!

I have the following code snippet:

DataTable tblCustomersTbl = tblCustomerAd.GetDataByDAAPatId(strDAAPatID);

If I go to the adapter and run it using a valid strDAAPatID I get a record but if I run it from the code using the same value I get:
String or Binary data would be truncated

Any idea would be helpful!!!

Question by:JDL129
    LVL 74

    Accepted Solution

    You are passing a parameter to the database that is larger than the data type for that column will allow. Compare all of your column definitions to the sizes of the parameters being sent.

    Author Comment

    kaufmed!!!  Thanks for the post!!

    The length of the values in strDAAPatID is 9 and the length in the datatable Customer is 9.
    Do I need to trim the variable?

    LVL 74

    Expert Comment

    by:käµfm³d 👽
    No, you shouldn't if the data going to the DB is equal (or less than) the length of the data allowed by the column. Is that the *only* parameter going to the database?

    Author Comment

    Yes, that is the only parameter.  It is always 9 and the column width in sqlserver is nvarchar(50).

    Author Closing Comment

    Sorry for the delay but you were right on!!!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Hire Top Freelancers to Complete C# Projects

    Source the talented Expert Exchange community
    for top quality work on your C# projects.

    Hire the best. Collaborate easily. Get quality work.

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now