SqlParameter with size=0

A

Aurin

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.
 
A

Aurin

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?
 
M

Mary Chipman [MSFT]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top