PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET SqlParameter with size=0

Reply

SqlParameter with size=0

 
Thread Tools Rate Thread
Old 30-04-2008, 10:05 PM   #1
Aurin
Guest
 
Posts: n/a
Default SqlParameter with size=0


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
Old 01-05-2008, 05:17 PM   #2
Aurin
Guest
 
Posts: n/a
Default RE: SqlParameter with size=0

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
Old 01-05-2008, 05:49 PM   #3
Mary Chipman [MSFT]
Guest
 
Posts: n/a
Default Re: SqlParameter with size=0

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 <Aurin@nospam.nospam> 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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off