oledbtype to system.type RRS feed

  • Question




    is there away to cast oledbtype to .net types e.g.:


    System.Data.OleDb.OleDbType.Char is mapped on the .Net type String  i want to retrieve the mapped .net type in this case type String.





    Thursday, October 18, 2007 8:38 AM

All replies

  • What exactly do you need to do? If you need to get data from the parameter, then .NET will do casting for you automatically when application reads or assigns data from/to parameter, so you do not need to do explicit conversion.


    Thursday, October 18, 2007 10:45 AM
  • i have my own object structure Column contains a property oledbtype and i'm creating manually datatable containing the specified datacolumn from my own object structure it cannot be done automatic. The code looks like this:



    c.oleDbType = (System.Data.OleDb.OleDbType)Enum.Parse(new System.Data.OleDb.OleDbType().GetType(), wsColumn.datatype);

    c.maxLength = wsColumn.maxlength;

    c.isAutoIncrement = wsColumn.autoincrement;

    dataColumn.DataType = c.oleDbType; <--- here needs to be casted





    Thursday, October 18, 2007 11:00 AM
  • To avoid explicit cast when you assign I believe you would need to create two properties for your Column class - one will keep DbType and would be of System.Data.DbType (not OleDbTyle) and another one read-only ColumnType, which would return .NET type. In this case all the casting will be done inside of the Column class when you assign value to DbType, but use ColumnType when you need to assign.


    Friday, October 19, 2007 10:34 AM