Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Querying a DataSet object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Savas - 09 Aug 2007 00:05 GMT
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
Peter Bromberg [C# MVP] - 09 Aug 2007 01:02 GMT
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

> 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:
[quoted text clipped - 20 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***
Peter Savas - 10 Aug 2007 22:17 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.