How to determine the DbType of a DbParameter when passing null values

M

Martin Horst

Hi,

I've got a problem with SQL update statements when I pass null values
(or better let's say DbNull values) to a DbParameter derived class (in
my case, I'm using an SQL Server database).
When I pass the DbNull value to the Value property, the DbType of the
DbParameter object is still string. If I try to write into a binary
field ( varbinary(max) ), I got an exception that the convertion between
varchar and varbinary is not possible. So in that case I have to set the
DbType by my own. My question is now, how do I get the DbType from an
..Net type. I want to be this generic, so I can use my methods with other
databases. I couldn't find anything usefull in the MSDN documentation.
If someone can get me some hints how to solve this, I would appreciate
this. Or maybe I'm on the wrong path. I'm not sure for the moment.

Thanks in advance
Martin
 

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