[dba-VB] c# - manipulating datasets in memory

James Barash james at fcidms.com
Fri Feb 19 14:05:34 CST 2010


John:

I don't have the syntax for C# but in VB, you can use LINQ to create a union of two datatables in memory. 

Assuming you have the two datatables dt1 and dt2:

        Dim unionqry = (From p1 In dt1 Select p1).Union(From p2 In dt2 Select p2)

You should be able to use unionqry in your fixed width writer, or you could convert it to a datatable using its method: CopyToDataTable.

Hopefully, that should give you a good starting point.

James Barash


-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Friday, February 19, 2010 2:28 PM
To: VBA
Subject: [dba-VB] c# - manipulating datasets in memory

I have written a C# fixed width file export for a specific purpose, exporting name / address orders for a client.

The data comes from a specific view of a SQL Server order database.  I need to insert a small set of additional "seed names" in the result set.  For technical reasons I really want to do this as I am writing the file to disk.  IOW it would be good if I could pull the order names into a data reader, union the seed names, sort on zip and write the data reader out to disk (fixed width file).

The fixed width writer code is written and functions just fine but ATM I am doing a klugy merge back in the database to get the seed names in before the writer ever gets the list of names to write.

So...

I know that supposedly .Net and SQL Server is all about disconnected recordsets and all of that. 
How would I go about pulling two datasets with the exact same fields (order and seed names) and then union them in memory before writing that union to file?

Any ideas?

--
John W. Colby
www.ColbyConsulting.com
_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com





More information about the dba-VB mailing list