I'm attempting to write a generic function for populating compound keys in a few tables of my database.
Unfortunately, I'm limited to using an OleDbConnection
so can't make use of many of the niceties of the SqlConnection
(and related) classes.
As part of this effort, I need to be able to convert generic system types (which will always be primitive string
, int
etc) to their OleDbType
enum counterparts.
I've viewed this question which has several suggestions in it: primarily, to use a class map. This approach would work fine however, it strikes me as strange that there would be no pre-built and pre-tested component of the .NET Framework that would do this significantly better than any code I would write would. I also dislike reinventing the wheel. The second approach suggested was to utilise the Parameter.ConvertTypeToDbType
method in System.Web
namespace (a stupid place to put it IMHO but I digress). This appears to work fine however, it yields a DbType
enum rather than an OleDbType
which I fear may cause compatibility issues.
My current attempt to utilise this approach looks like this:
OleDbParameter searchValueOne = new OleDbParameter("@searchValueOne", System.Web.UI.WebControls.Parameter.ConvertTypeCodeToDbType(Type.GetTypeCode(typeof(T1))));
So my question would be, is there a similar built in function that provides an OleDbType
as opposed to a DbType
or is going with a TypeMap
simply going to be the best approach?