473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Querying a DataSet object

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


*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '07 #1
2 1433
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

"Peter Savas" wrote:
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


*** Sent via Developersdex http://www.developersdex.com ***
Aug 9 '07 #2
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

*** Sent via Developersdex http://www.developersdex.com ***
Aug 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Abhishek Srivastava | last post by:
Hello All, Suppose if I have a SQL query like select p.ID, p.NAME, p.UNIT_PRICE, o.QUANTITY from PRODUCT p ORDERS o where p.ID = X AND P.ID = O.ID Here one product can have many orders....
3
by: MDB | last post by:
I'd normally Google for a question like this, and hope to snag a few examples along with the answer, but this time I can't see to get the keywords specific enough. Or I'd ask coworkers, but...
1
by: Michel Moreno | last post by:
Hi everybody, i would like to query the Index Catalog, for a site, as describe in the article: http://support.microsoft.com/default.aspx?scid=kb;en-us;820105 But i'm having an error, I don't know...
6
by: Fred | last post by:
I want to use a dataset so that I can obtain data from a number of sources and put it into one table. Using dataadaptors this seems to work well. Now I have a table (Forecast) in the dataset with...
1
by: sharmaajay | last post by:
hi all, i want to know whether we can make a dataextract function in global page(global.asax) though a query and.. then for each individual .aspx page can we query tht dataset instead of creating...
4
by: onecorp | last post by:
I have a SQL table comprised of 31 columns. The first column is simply an id column, the next 30 columns are labelled ,.... The numerical columns have a tinyint type and the data stored is either...
5
by: sql_er | last post by:
Guys, I have an XML file which is 233MB in size. It was created by loading 6 tables from an sql server database into a dataset object and then writing out the contents from this dataset into an...
2
by: Steven Cheng [MSFT] | last post by:
Hi Cj, I also noticed that the "Act" variable here seems hasn't been declared(or declared anywhere else?). I've try building the same code and got the same result and the "Operator '+' cannot be...
4
by: mcmahon | last post by:
Hi, I have a MS Access DB with a query that I need to display in vb but am not too sure on how to go about it. The query has some criteria - i.e you have to input a date to run the query. I think...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.