Querying a DataSet object

P

Peter Savas

I am new to programming in C#, but have been a VB coder for 16 years,
and am facing a problem which I could use some help with:

I have an XML file which I am reading into a C# DataSet object with the
following line of code:

ds.ReadXML(InputFileName);

Against this DataSet, I need to be able to run SQL Queries, with the
ultimate goal of inserting (almost) all of the data in the DataSet into
table structures on an SQL Server.

Is there a way to execute T-SQL statements against the DataSet object?
In particular, I need to exclude certain records based on CAST
transformations, and then INSERT the remaining records in the DataSet
into the server-hosted tables. I would prefer not to step through the
records one at a time if possible.

Any help would be appreciated.

Thank you,
pete
 
G

Guest

Actually there are probably a half-dozen ways to skin this cat, but the one
I'd try first is to pass your DataSet into the Update method of a
SqlDataAdapter with a properly configured Update or Insert Command. You can
use a stored procedure with this, and if the SQL is constructed properly,
only the rows that you want will be inserted.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com
 
P

Peter Savas

Peter,

I've been trying to do as you suggested and use the SqlDataAdapter, but
so far I've not had any luck with getting it to work. If it wouldn't be
too much of a bother, could you give me some sample code to illustrate
the method you're thinking of? Particularly, I really need to know how
to load the DataAdapter's DataSet with the DataSet from the XML file.

Thanks in advance,
pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top