Query in memory dataset c# 2

  • Thread starter Thread starter deciacco
  • Start date Start date
D

deciacco

Is there a way to query an in-memory dataset with sql or can you only
work with the individual table through DataTable.Select()?

How can you go about getting the identity of a new record if you use an
autoincrement primary key on the datatable?

Thanks
 
Unless you have an in-memory SQL engine (like SQL Server Compact Edition)
all you can do is use the Select, Find etc. features of the
DataTable/DataView classes.

AFA retrieving the new Identity value an additional query needs to be
executed to execute SELECT @@Identity or (better yet) SCOPE_IDENTITY().

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 
www.queryadataset.com provides a complete set of SQL commands for
interacting with a Dataset in the same way you interact with a database. A
standard .NET Provider interface is also close to being ready.

To get the next value of an identity column, use the following technique.
First, use DataTable.NewRow to get the next value. Unfortately, this will
leave a gap the next time you insert, so you have to set the
autoincrementstep to its negative value, request a new row, then reset the
autoincrementstep.

row = dt.NewRow

dt.Columns(id).AutoIncrementStep = -1
dt.NewRow()
dt.Columns(id).AutoIncrementStep = 1
Hope this helps

Adrian Moore
http://www.queryadataset.com
Microsoft MVP - Windows Networking (P2P)
 
Its also interesting to note that SQL-Server does not allow multiple
identity columns in a table while a Dataset does.

Ad.
 
Back
Top