PC Review


Reply
Thread Tools Rate Thread

SqlParameter with size=0

 
 
Aurin
Guest
Posts: n/a
 
      30th Apr 2008
I used the SqlDataAdapter Configuration Wizard to generate a new
SqlDataAdapter. I used Sql statements and typed a simple "select * from
table1" for the sql. In the generated code all the SqlParameters had size=0.
WHY? I have done this in the past, very recently in fact, with no problem.
I tried this on 2 different PCs and using different tables on different
database servers. Same result.
 
Reply With Quote
 
 
 
 
Aurin
Guest
Posts: n/a
 
      1st May 2008
after further research I realize that this is how SqlDataAdapters are done in
2005. At this point I have some that work. However, I have another one that
returned a SqlException "String or binary data would be truncated. ". I
resolved the problem by entering the data lengths into the SqlParameters. So
now I assume that if size=0, the size will be obtained from the dbType and
the length of the value. Is this true?
 
Reply With Quote
 
Mary Chipman [MSFT]
Guest
Posts: n/a
 
      1st May 2008
The size for input parameters for string or binary data is inferred
from the parameter value at run time. So if you're creating the
parameter using a wizard, SqlParameter has no way of knowing the
actual size of the data. If you set the size manually, and the size is
smaller than the data at run time, then the data will be trunated. So
if you're getting the odd exception, you might be better off simply
omitting the size for string and binary data.

-Mary

On Thu, 1 May 2008 09:17:33 -0700, Aurin <(E-Mail Removed)> wrote:

>after further research I realize that this is how SqlDataAdapters are done in
>2005. At this point I have some that work. However, I have another one that
>returned a SqlException "String or binary data would be truncated. ". I
>resolved the problem by entering the data lengths into the SqlParameters. So
>now I assume that if size=0, the size will be obtained from the dbType and
>the length of the value. Is this true?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SqlParameter.Size - When to use? Amy L. Microsoft ADO .NET 1 2nd Oct 2007 07:03 PM
Problem with SQLParameter data type (because 'System.Data.SqlClient.SqlParameter' is not derived from 'StoreBO.StoreBackOffice.SqlParameter'. ) Stacey Levine Microsoft VB .NET 3 16th Mar 2005 03:39 AM
must set .Size property for output SQLParameter John A Grandy Microsoft ADO .NET 2 2nd Feb 2005 02:37 AM
SQLParameter.Size for output param John A Grandy Microsoft ADO .NET 0 25th Feb 2004 12:09 PM
SqlParameter SqlDBType.text size Michael Microsoft ADO .NET 1 7th Jan 2004 11:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:40 PM.