ADO Type Conversion 
Author Message
 ADO Type Conversion

Hello

newbie here. i'm wondering how this is solved in a more generic way.
i have a class where properties must be filled with database values coming
from a single row in this case.

one way i tried is using a datareader.
bd is a instance of the class, rdr is the datareader, AnzAdrBotenCH is a
Int32 property

bd.AnzAdrBotenCH=rdr.GetInt32(0);

or with a Datatable/Datarow(dr)
bd.AnzAdrBotenCH=Convert.ToInt32(dr["sortAnzAdrBoten"])

Both work. But it doesn't seem right that i have to explicitly write down
the Datatype even though at least the Datarow knows perfectly well that the
column from the Database is Int32. How can the value be assigned without
specifying the datatype everytime. could
dr["sortAnzAdrBoten"].GetType()
lead to a solution ? or am i way off here ? :)

TIA !

Beat

--

** Order is an illusion - Chaos is the reality **



Sat, 20 Nov 2004 00:42:57 GMT  
 ADO Type Conversion
Beat,

    Basically, you can cast the value returned by the data row to the type
you want, like so:

ba.AnzAdrBotenCH = (int) dr["sortAnzAdrBoten"];

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Hello

> newbie here. i'm wondering how this is solved in a more generic way.
> i have a class where properties must be filled with database values coming
> from a single row in this case.

> one way i tried is using a datareader.
> bd is a instance of the class, rdr is the datareader, AnzAdrBotenCH is a
> Int32 property

> bd.AnzAdrBotenCH=rdr.GetInt32(0);

> or with a Datatable/Datarow(dr)
> bd.AnzAdrBotenCH=Convert.ToInt32(dr["sortAnzAdrBoten"])

> Both work. But it doesn't seem right that i have to explicitly write down
> the Datatype even though at least the Datarow knows perfectly well that
the
> column from the Database is Int32. How can the value be assigned without
> specifying the datatype everytime. could
> dr["sortAnzAdrBoten"].GetType()
> lead to a solution ? or am i way off here ? :)

> TIA !

> Beat

> --

> ** Order is an illusion - Chaos is the reality **



Sat, 20 Nov 2004 01:59:43 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Type conversion-How can I convert cstring data type to char*

2. Mapping ADO data types with C++ data types

3. OLEDB RowSet to ADO Recordset conversion

4. Looking for XML to ADO conversion

5. Conversion of values while filling ADO.NET DataSet object

6. a function-style conversion to a built-in type can only take one argument

7. Type conversion question

8. Conversion from Object to another type

9. /checked and Checked conversions of basic types!

10. Explicit Type Conversions

11. data type conversion

12. Type conversion

 

 
Powered by phpBB® Forum Software