Hi,

I am new to .net. I think .NET provides what I need, but I don't
know how to implement it.

What I need is simply associating an object with a database
table. I would like to load "objects" from table, and I would like to
modify or delete objects, without dealing with database in anywhere. In
other words; I do not want to write SQL query for any of those
operations. Let me give you an example (in C++/CLI):

ref class MessageBase abstract
{
String^ m_strFrom;
String^ m_strBody;
String^ m_strSubject;
DateTime m_dtRecSent;
DateTime m_dtReplied;
DateTime m_dtForwarded;
MessageTypes m_mtType;
public:
property String^ From { String^ get(); void set(String^); }
property String^ Body { String^ get(); void set(String^); }
property String^ Subject { String^ get(); void set(String^); }
property DateTime ReceivedDate { DateTime get(); void
set(DateTime); }
property DateTime RepliedDate { DateTime get(); void
set(DateTime); }
property DateTime Forwarded { DateTime get(); void set(DateTime);
}
property DateTime SentDate { DateTime get(); void set(DateTime); }
property MessageTypes MessageType { MessageType get(); void
set(MessageTypes); }
};

I have got a table to store this information. I would like to
load "messages" from table at startup, through a factory (another
recommendation?). I have prepared a typed dataset, too, but I couldn't
associate it with this class. What I have done previously in C++ was a
simple adapter. Adapter was acting like a "message object" to the
application itself, any changes in the object automatically goes
database, too. As far as I have heard, after associating this class
with a table, I will not write any SQL statement.

I would be very happy, if you could enlighten me about this type
of association. I am using .NET Framework 2.0 (of course, since I am
using C++/CLI) and I do not have a performance concern with this
operation (I have heard that this type of association of an object with
a dataset is far slower than SqlDataReader way). Database is SQLite, I
am using ADO.NET class library to access database from .NET (I have
native library as well).

Thanks!
Jason

Re: How to bind an object to a table by Cor

Cor
Fri Dec 30 01:28:03 CST 2005

Bumperman,

There are hundreds of types of tables in Net, I assume now that you mean a
database table.

An object is the rawest part of Net. In fact the base class for all other
types. Not really the one for binding. It has not any property that you can
bind.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemobjectmemberstopic.asp

However I assume that you mean an from Object inherited ObjectType. From
that you can bind all properties if the mechanisme is made in the consuming
type.

>I will not write any SQL statement.

Do you mean write explicitly and implicitely. Than it is impossible. .Net
and SQL are working thight together where Transact SQL is used.

> I would be very happy, if you could enlighten me about this type
> of association. I am using .NET Framework 2.0 (of course, since I am
> using C++/CLI) and I do not have a performance concern with this
> operation (I have heard that this type of association of an object with
> a dataset is far slower than SqlDataReader way). Database is SQLite, I
> am using ADO.NET class library to access database from .NET (I have
> native library as well).

The SQLDataReader is fairly quicker than using the SQLDataAdapter, which is
in fact a class holding a lot of methods to create, update, remove, select
dataobjects for you (datatable/dataviews, datasets, datarows). Those
dataobjects and the dataadapter have all kind of methods build in. One of
those methods in the dataadapter is using is the datareader.

I hope this gives some ideas

Cor