By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,184 Members | 1,639 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,184 IT Pros & Developers. It's quick & easy.

IFormatProvider for non-custom format Problem

P: n/a
Has anyone come across a solution to this ?

To format a value into an Sql Server sql string, I want to use the call
Convert.ToString( value, new MyFormatProvider() );

Why I have to do this myself is because for boolean values the sql string
contain 1 or 0 instead of 'true' or 'false' and because the dotnet DateTime
has a
greater range than Sql Server datetime.

I write a class MyFormatProvider, that implements IFormatProvider,
ICloneable and ICustomFormatter. As seen in some samples within
IFormatProvider.GetFormat() I check the type and on typeof(NumberFormatInfo)
I return my own formatter.

Well, my ICustomFormatter.Format() never gets called, instead a 'Specified
Cast is not valid' exception is thrown. I cannot derive the NumberFormatInfo
to modify it, because it is sealed. And I don't want to define a custom
format string, because then I could simply do the whole formatting on my

Any ideas ?

Thanks in advance!

Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.