PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Accessing data on the fly

Reply

Accessing data on the fly

 
Thread Tools Rate Thread
Old 22-03-2005, 06:09 PM   #1
=?Utf-8?B?TW9oZWI=?=
Guest
 
Posts: n/a
Default Accessing data on the fly


Hi All,

I am creating a DataTable on the fly and populate it in the code for example
like:

DataTable dT = new DataTable();
dT.Columns.Add("col1");
dT.Columns.Add("col2");
DataRow dR = dT.NewRow();
dR["col1"] = "val1";
dR["col2"] = "val2";

Is there anyway to run a select statement against this table? For example
like:

select * from dT order by col1?

What will be the connection object?

Thanks,

Moheb



.....



  Reply With Quote
Old 22-03-2005, 06:34 PM   #2
Marina
Guest
 
Posts: n/a
Default Re: Accessing data on the fly

No, there is not.

The best you can do is put a dataview on top of the datatable and specify a
filter and a sort.

A datatable is not an in memory database. Very important to remember that.

"Moheb" <Moheb@discussions.microsoft.com> wrote in message
news:6FBF2738-C1D1-4F04-BE4B-AC2D97E3B69D@microsoft.com...
> Hi All,
>
> I am creating a DataTable on the fly and populate it in the code for
> example
> like:
>
> DataTable dT = new DataTable();
> dT.Columns.Add("col1");
> dT.Columns.Add("col2");
> DataRow dR = dT.NewRow();
> dR["col1"] = "val1";
> dR["col2"] = "val2";
>
> Is there anyway to run a select statement against this table? For example
> like:
>
> select * from dT order by col1?
>
> What will be the connection object?
>
> Thanks,
>
> Moheb
>
>
>
> ....
>
>
>



  Reply With Quote
Old 22-03-2005, 06:38 PM   #3
Andrew Conrad
Guest
 
Posts: n/a
Default RE: Accessing data on the fly

You can't run a select statement, but you can pass an expression to the
DataTable.Select method. See:

http://msdn.microsoft.com/library/d...-us/cpref/html/
frlrfsystemdatadatatableclassselecttopic.asp

Andrew Conrad
Microsoft Corp
http://blogs.msdn.com/aconrad/

  Reply With Quote
Old 22-03-2005, 08:15 PM   #4
=?Utf-8?B?TW9oZWI=?=
Guest
 
Posts: n/a
Default Re: Accessing data on the fly

Thx for the reply. Actually it depends on what you mean by memory. An
automatic variable of type DataTable is a piece of memory on the stack. It'd
be nice if you could run a select query on it (more than just sort and filter
expressions, for example like count, sum, etc.) just like you are running one
on "hard" object pieces such as sql tables. For the problem I am working on I
have to mimic this by extra coding whereas I should have been able write a
single line of code containing a select statement. Hopefully in the next
release of adonet by MS!

Regards,

Moheb

"Marina" wrote:

> No, there is not.
>
> The best you can do is put a dataview on top of the datatable and specify a
> filter and a sort.
>
> A datatable is not an in memory database. Very important to remember that.
>
> "Moheb" <Moheb@discussions.microsoft.com> wrote in message
> news:6FBF2738-C1D1-4F04-BE4B-AC2D97E3B69D@microsoft.com...
> > Hi All,
> >
> > I am creating a DataTable on the fly and populate it in the code for
> > example
> > like:
> >
> > DataTable dT = new DataTable();
> > dT.Columns.Add("col1");
> > dT.Columns.Add("col2");
> > DataRow dR = dT.NewRow();
> > dR["col1"] = "val1";
> > dR["col2"] = "val2";
> >
> > Is there anyway to run a select statement against this table? For example
> > like:
> >
> > select * from dT order by col1?
> >
> > What will be the connection object?
> >
> > Thanks,
> >
> > Moheb
> >
> >
> >
> > ....
> >
> >
> >

>
>
>

  Reply With Quote
Old 22-03-2005, 08:24 PM   #5
Marina
Guest
 
Posts: n/a
Default Re: Accessing data on the fly

I mean memory on the stack, when i say memory.

I think it is easy to overlook the complexity in writing a query parser and
execution engine. This would typically include indexing, query rewriting,
optimizing, etc. This is what Oracle, SQL Server, etc, are for.

So again, I don't think you will see an in memory database, as it would
involve .NET basically containing SQL Server that could run in an app.

"Moheb" <Moheb@discussions.microsoft.com> wrote in message
news35DCF12-B9BE-40AA-BBDF-BF3727E07879@microsoft.com...
> Thx for the reply. Actually it depends on what you mean by memory. An
> automatic variable of type DataTable is a piece of memory on the stack.
> It'd
> be nice if you could run a select query on it (more than just sort and
> filter
> expressions, for example like count, sum, etc.) just like you are running
> one
> on "hard" object pieces such as sql tables. For the problem I am working
> on I
> have to mimic this by extra coding whereas I should have been able write a
> single line of code containing a select statement. Hopefully in the next
> release of adonet by MS!
>
> Regards,
>
> Moheb
>
> "Marina" wrote:
>
>> No, there is not.
>>
>> The best you can do is put a dataview on top of the datatable and specify
>> a
>> filter and a sort.
>>
>> A datatable is not an in memory database. Very important to remember
>> that.
>>
>> "Moheb" <Moheb@discussions.microsoft.com> wrote in message
>> news:6FBF2738-C1D1-4F04-BE4B-AC2D97E3B69D@microsoft.com...
>> > Hi All,
>> >
>> > I am creating a DataTable on the fly and populate it in the code for
>> > example
>> > like:
>> >
>> > DataTable dT = new DataTable();
>> > dT.Columns.Add("col1");
>> > dT.Columns.Add("col2");
>> > DataRow dR = dT.NewRow();
>> > dR["col1"] = "val1";
>> > dR["col2"] = "val2";
>> >
>> > Is there anyway to run a select statement against this table? For
>> > example
>> > like:
>> >
>> > select * from dT order by col1?
>> >
>> > What will be the connection object?
>> >
>> > Thanks,
>> >
>> > Moheb
>> >
>> >
>> >
>> > ....
>> >
>> >
>> >

>>
>>
>>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off