tantormedia
asked on
DBNull.Value for a string OdbcParameter
Dear experts,
I want to execute a stored procedure, and some of the string parameters may be empty. Instead of passing to the stored procedure an empty string for saving in my database, I want to pass a DBNull.Value. I tried the following:
parameters[3] = new OdbcParameter("pOrigValue" , (oldFieldsValues[ctrl.ID] == string.Empty) ? DBNull.Value : oldFieldsValues[ctrl.ID]);
But I am getting an error:
error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DBNull' and 'string'
Could you please tell me how I could do it correctly?
Thanks.
I want to execute a stored procedure, and some of the string parameters may be empty. Instead of passing to the stored procedure an empty string for saving in my database, I want to pass a DBNull.Value. I tried the following:
parameters[3] = new OdbcParameter("pOrigValue"
But I am getting an error:
error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DBNull' and 'string'
Could you please tell me how I could do it correctly?
Thanks.
try sending null instead of DBNull.Value - odbc should be smart enough to convert it for you.
ASKER
kaufmed,
I tried it, and it stored an empty string instead of null .
I tried it, and it stored an empty string instead of null .
ASKER
packratt_jk,
This also stores an empty string.
This also stores an empty string.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks.
NP. Glad to help :)
Open in new window