kwh3856
asked on
Operator '??' cannot be applied to operands of type 'string' and 'int'
I am getting this error message when trying to save data from a variable into a field in a table. What I do not under stand is the field type in the database is INT and I am also performing an INT conversion. Why is it giving me this error if both are integers?
Here is the code.
Here is the code.
myPatPhones.SourceOfRecord = Convert.ToInt32(patient.d.NPI ?? 0);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My mistake. Try this:
myPatPhones.SourceOfRecord = Convert.ToInt32(patient.d.NPI ?? "0");
Thanks for the A, but it wasn't deserved. I delved a bit deeper in it and found the above. The thing is this:
- The ?? operator can be used with nullable types, but then the left-hand and right-hand side must be of the same type
- The ?? operator can also be used with reference types (like a string). But then, too, the left-hand and the right-hand side must be of the same type.
- The ?? operator can not be used with nullable strings... Don't know why.
> but it wasn't deserved
yet ;)
yet ;)
ASKER
Thanks. But I disagree:)
You solved my problem:)
Thanks
Kenny
You solved my problem:)
Thanks
Kenny
ASKER
Thanks
Kenny