C# error message when getting a table from an adapter

Posted on 2012-09-07
Medium Priority
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
  • 3
  • 2
LVL 75

Accepted Solution

käµfm³d   👽 earned 1000 total points
ID: 38378305
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

ID: 38378326
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 75

Expert Comment

by:käµfm³d 👽
ID: 38378332
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

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

Author Closing Comment

ID: 38424902
Sorry for the delay but you were right on!!!!!

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

807 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