Storing Object instances and reteriving Object instances 
Author Message
 Storing Object instances and reteriving Object instances

Hi all,
We are trying to store object in database
(Access Database and the field type is Ole Object).

we are able to insert the object(In database ,value is
show as binary)

When we try to get back the data using
OleDbDataReader.GetValue and try to store the return
value in Object class object , it is giving an invalidtype
cast exception when we do a convertion from object to our
user defined class object(UserDetailsClass)

Here is the code

OleDbDataReader xReader;
this.oleDbSelectCommand1.Connection.Open();
oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand
(this.oleDbSelectCommand1.CommandText,this.oleDbSelectComma
nd1.Connection);
xReader = oleDbSelectCommand1.ExecuteReader();
while(xReader.Read())
{
 Object obj1;
 obj1 = xReader.GetValue(1);
UserDetailsClass UDC;
UDC = (UserDetailsClass) (obj1);///Exception is raised
Label1.Text = UDC.sName;
Label2.Text = UDC.sCompany;

Quote:
}



Fri, 05 Nov 2004 22:49:03 GMT  
 Storing Object instances and reteriving Object instances
Durga,

    How do you get the value into the DB I wonder?

    You can not do it this way, you will need to use an instance of a
BinaryFormatter class (which is what I assume you used to serialize the
object) and then deserialize the bits from the BLOB.  My guess is that it
gets assigned to the object as an array of bytes.

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Hi all,
> We are trying to store object in database
> (Access Database and the field type is Ole Object).

> we are able to insert the object(In database ,value is
> show as binary)

> When we try to get back the data using
> OleDbDataReader.GetValue and try to store the return
> value in Object class object , it is giving an invalidtype
> cast exception when we do a convertion from object to our
> user defined class object(UserDetailsClass)

> Here is the code

> OleDbDataReader xReader;
> this.oleDbSelectCommand1.Connection.Open();
> oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand
> (this.oleDbSelectCommand1.CommandText,this.oleDbSelectComma
> nd1.Connection);
> xReader = oleDbSelectCommand1.ExecuteReader();
> while(xReader.Read())
> {
>  Object obj1;
>  obj1 = xReader.GetValue(1);
> UserDetailsClass UDC;
> UDC = (UserDetailsClass) (obj1);///Exception is raised
> Label1.Text = UDC.sName;
> Label2.Text = UDC.sCompany;
> }



Fri, 05 Nov 2004 22:50:54 GMT  
 Storing Object instances and reteriving Object instances
You are right it is assigned as array of bytes, as while reading the
data we are getting the data as array of bytes This we are trying it for
the first time . we will try to use BinrayFormatter Class and get back
to you , in case we have any problem.

Thanks
Durga

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Fri, 05 Nov 2004 23:22:55 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Single-instance object starts multiple instances

2. Linklabel problem Object reference not set to an instance of an object

3. NullReferenceException : Object reference not set to an instance of an object

4. Object reference not set to an instance of an object

5. Object reference not set to an instance of an object

6. How to Convert the Name of an Object Instance Into an Object Reference

7. Error: Object reference not set to an instance of an object

8. Object refernce not set to an instance of an object

9. Exposing instances of ATL objects through a base object (or another)

10. Casting a object instance to a unknown type.

11. How do I gain access to an existing object instance

12. Create instance of class with object Type

 

 
Powered by phpBB® Forum Software