Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 26th, 2006, 02:45 PM
MurdockSE
Guest
 
Posts: n/a
Default What is the quickest way to get an xml based dataset to add entries to SQL Server?

Because there is no 'datareader' involved, what is the most efficient
way to get an XML based dataset to be added to an SQL server dataset? I
would hate to have to create a new SQL connection and iterate through
making "executenonquery" for each row in the dataset. That seems
horribly in-efficient. I know of no other way to get an xml based
dataset to push data to the database though. Any pointers?

Thanks for any pointers,
Peter Robbins
Freelance Programmer C#/PHP

  #2  
Old July 26th, 2006, 05:05 PM
John Saunders
Guest
 
Posts: n/a
Default Re: What is the quickest way to get an xml based dataset to add entries to SQL Server?

"MurdockSE" <murdock@nc.rr.comwrote in message
news:1153922058.675709.165630@h48g2000cwc.googlegr oups.com...
Quote:
Because there is no 'datareader' involved, what is the most efficient
way to get an XML based dataset to be added to an SQL server dataset? I
would hate to have to create a new SQL connection and iterate through
making "executenonquery" for each row in the dataset. That seems
horribly in-efficient. I know of no other way to get an xml based
dataset to push data to the database though. Any pointers?
Use a DataAdapter and do an Update. Just make sure all the rows youi want
added are marked as being in Add state.

John


  #3  
Old July 26th, 2006, 06:05 PM
MurdockSE
Guest
 
Posts: n/a
Default Re: What is the quickest way to get an xml based dataset to add entries to SQL Server?

Excuse my ADO.NET naivite (newbie alert*) but how do I iterate the
existing ds and set all of the rows to ADD?

For example:

DataSet ds = new DataSet("MyRecords");
ds.ReadXml(xmlfilename);

And the seperate SQL creations would be similar to this:

using System.Data.SqlClient;
using System.Data;

string strDBConnection = "server=(local);database=DatabaseName;user
id=UserName;password=Pwd;connection reset=false;connection
lifetime=5;Trusted_Connection=Yes;"
SqlConnection dbConnection;
dbConnection = new SqlConnection(strDBConnection);

string strSelectSql = "Select * from
[DatabaseName].[OwnerName].[TableName] order by FieldName";

//Open the connection
dbConnection.Open();

//Create a command
SqlCommand selectSqlCommand = new
SqlCommand(strSelectSql,dbConnection);
SqlDataAdapter sqlData = new SqlDataAdapter(selectSqlCommand);
DataSet dsSelectData = new DataSet();
sqlData.Fill(dsSelectData);

How do I get the ds into the sqlData adapter set to ADD each row?


Peter Robbins

  #4  
Old July 26th, 2006, 09:05 PM
MurdockSE
Guest
 
Posts: n/a
Default Re: What is the quickest way to get an xml based dataset to add entries to SQL Server?

I got the answer/s I was looking for here:

http://groups.google.com/group/micro...9226fef?hl=en&

Thanks again. You basically stated the same thing. My naive self just
needed a little extra push on the particulars. Thanks.

Peter Robbins

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles