473,806 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to send an xml dataset to a Stored Procedure in mssql

a
how to send an xml dataset to a Stored Procedure in mssql

I have an xml file that I read into a dataset.
and I'm trying to use a stored procedure (see SPROC #1 below)
that inserts this xml dataset into an sql table via OpenXML.
Nothing gets inserted into the sql table except nulls,
so I think that perhaps I'm not actually sending the (xml)
dataset to the SPROC.

The code below fails on this line: sqlCommand1.Exe cuteNonQuery();

(The SPROC works fine when I run it in Query Analyzer
and SET the xml file directly as a string. See the SPROC #2 below)

What do I need to do to send the xml datset to the SPROC?

Thank you.

Paul

============ C# ===============

DataSet dsInsiderOwners = new DataSet("owners hipDocument");
string filePath = "D:\\SEC\\Progr amming\\SEC DataBots\\SEC DataBot Test
Files\\Form 4\\From QS.xml";

dsInsiderOwners .ReadXml(filePa th);

string myConnectionStr ing = "workstatio n id=AMD;packet
size=4096;integ rated security=SSPI;d ata source=AMD;pers ist security
info=False;init ial catalog=MyDatab ase";
SqlConnection sqlConnection1 = new SqlConnection(m yConnectionStri ng);

SqlCommand sqlCommand1 = new SqlCommand();
sqlCommand1.Con nection = sqlConnection1;
sqlCommand1.Com mandType = System.Data.Com mandType.Stored Procedure;
sqlCommand1.Com mandText = "_sp_Insert_For m_004_XML_templ ate_07";
sqlCommand1.Par ameters.Add(new
System.Data.Sql Client.SqlParam eter("@Form_004 ", System.Data.Sql DbType.NText));
sqlCommand1.Par ameters[0].Value = dsInsiderOwners ;

sqlConnection1. Open();
sqlCommand1.Exe cuteNonQuery();
sqlCommand1.Con nection.Close() ;

============ SPROC #1 - accepts xml as a variable =============== ===

CREATE PROC _sp_Insert_Form _004_XML_templa te_07 (@Form_004 nText)

AS

DECLARE @iDoc int--............... ............... .............va riable to
hold parsed xml stream

EXEC sp_xml_prepared ocument @iDoc OUTPUT, @Form_004--.....create parsed xml
stream

SELECT * INTO Form_004_A--............... ............... ......To Insert Into
A NEWLY Created Table

FROM OPENXML(@iDoc, 'ownershipDocum ent/issuer',3)

WITH (issuerCik char(10) , issuerName char(40) , issuerTradingSy mbol
char(10))

EXEC sp_xml_removedo cument @iDoc

GO
============ SPROC #2 - for QueryAnalyzer (xml set as a string)
=============== ===

DECLARE @iDoc int

DROP TABLE Form_004_A

DECLARE @XMLDoc varchar(8000)
SET @XMLDoc = '<?xml version="1.0"?>
<ownershipDocum ent>
<schemaVersion> X0202</schemaVersion>
<documentType>4 </documentType>
<periodOfReport >2005-04-29</periodOfReport>
<notSubjectToSe ction16>0</notSubjectToSec tion16>
<issuer>
<issuerCik>0000 796343</issuerCik>
<issuerName>ADO BE SYSTEMS INC</issuerName>
<issuerTradingS ymbol>ADBE</issuerTradingSy mbol>
</issuer>
</ownershipDocume nt>'
EXEC sp_xml_prepared ocument @iDoc OUTPUT, @XMLDoc

SELECT * INTO Form_004_A

FROM OPENXML(@iDoc, 'ownershipDocum ent/issuer',3)
WITH (issuerCik char(10) , issuerName char(40) , issuerTradingSy mbol
char(10))

EXEC sp_xml_removedo cument @iDoc

SELECT * FROM Form_004_A

GO

Nov 12 '05 #1
1 4930
Hi,

Use IO Classes and Send the XML Content to the value property of the
parameter.

Regards,

Prasad Dannani.

"a" <a@discussions. microsoft.com> wrote in message
news:DE******** *************** ***********@mic rosoft.com...
how to send an xml dataset to a Stored Procedure in mssql

I have an xml file that I read into a dataset.
and I'm trying to use a stored procedure (see SPROC #1 below)
that inserts this xml dataset into an sql table via OpenXML.
Nothing gets inserted into the sql table except nulls,
so I think that perhaps I'm not actually sending the (xml)
dataset to the SPROC.

The code below fails on this line: sqlCommand1.Exe cuteNonQuery();

(The SPROC works fine when I run it in Query Analyzer
and SET the xml file directly as a string. See the SPROC #2 below)

What do I need to do to send the xml datset to the SPROC?

Thank you.

Paul

============ C# ===============

DataSet dsInsiderOwners = new DataSet("owners hipDocument");
string filePath = "D:\\SEC\\Progr amming\\SEC DataBots\\SEC DataBot Test
Files\\Form 4\\From QS.xml";

dsInsiderOwners .ReadXml(filePa th);

string myConnectionStr ing = "workstatio n id=AMD;packet
size=4096;integ rated security=SSPI;d ata source=AMD;pers ist security
info=False;init ial catalog=MyDatab ase";
SqlConnection sqlConnection1 = new SqlConnection(m yConnectionStri ng);

SqlCommand sqlCommand1 = new SqlCommand();
sqlCommand1.Con nection = sqlConnection1;
sqlCommand1.Com mandType = System.Data.Com mandType.Stored Procedure;
sqlCommand1.Com mandText = "_sp_Insert_For m_004_XML_templ ate_07";
sqlCommand1.Par ameters.Add(new
System.Data.Sql Client.SqlParam eter("@Form_004 ", System.Data.Sql DbType.NText)); sqlCommand1.Par ameters[0].Value = dsInsiderOwners ;

sqlConnection1. Open();
sqlCommand1.Exe cuteNonQuery();
sqlCommand1.Con nection.Close() ;

============ SPROC #1 - accepts xml as a variable =============== ===
CREATE PROC _sp_Insert_Form _004_XML_templa te_07 (@Form_004 nText)

AS

DECLARE @iDoc int--............... ............... .............va riable to
hold parsed xml stream

EXEC sp_xml_prepared ocument @iDoc OUTPUT, @Form_004--.....create parsed xml stream

SELECT * INTO Form_004_A--............... ............... ......To Insert Into A NEWLY Created Table

FROM OPENXML(@iDoc, 'ownershipDocum ent/issuer',3)

WITH (issuerCik char(10) , issuerName char(40) , issuerTradingSy mbol
char(10))

EXEC sp_xml_removedo cument @iDoc

GO
============ SPROC #2 - for QueryAnalyzer (xml set as a string)
=============== ===

DECLARE @iDoc int

DROP TABLE Form_004_A

DECLARE @XMLDoc varchar(8000)
SET @XMLDoc = '<?xml version="1.0"?>
<ownershipDocum ent>
<schemaVersion> X0202</schemaVersion>
<documentType>4 </documentType>
<periodOfReport >2005-04-29</periodOfReport>
<notSubjectToSe ction16>0</notSubjectToSec tion16>
<issuer>
<issuerCik>0000 796343</issuerCik>
<issuerName>ADO BE SYSTEMS INC</issuerName>
<issuerTradingS ymbol>ADBE</issuerTradingSy mbol>
</issuer>
</ownershipDocume nt>'
EXEC sp_xml_prepared ocument @iDoc OUTPUT, @XMLDoc

SELECT * INTO Form_004_A

FROM OPENXML(@iDoc, 'ownershipDocum ent/issuer',3)
WITH (issuerCik char(10) , issuerName char(40) , issuerTradingSy mbol
char(10))

EXEC sp_xml_removedo cument @iDoc

SELECT * FROM Form_004_A

GO

Nov 12 '05 #2

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

Similar topics

1
4238
by: Ryan | last post by:
I have two similar stored procedures which I'm running. One runs and one doesn't. I can run both with no problems in SQL Enterprise (7.0 standard) and have checked the permissions and am happy with them. Whilst the statements in each sp are different, I'm calling them in exactly the same way (using Delphi 5 Windows 2000). I don't get any trappable errors. I ran a trace on what was happening and I get two different set of results. This...
3
51739
by: Mike P | last post by:
Is it possible to return a dataset from a stored procedure, or would you need to write the SQL in your .cs file to return the dataset? Any assistance would be really appreciated. Cheers, Mike
2
2628
by: a | last post by:
how to send an xml dataset to a Stored Procedure in mssql I have an xml file that I read into a dataset. and I'm trying to use a stored procedure (see SPROC #1 below) that inserts this xml dataset into an sql table via OpenXML. Nothing gets inserted into the sql table except nulls, so I think that perhaps I'm not actually sending the (xml) dataset to the SPROC. The code below fails on this line: sqlCommand1.ExecuteNonQuery();
11
1949
by: Leon | last post by:
I have six textbox controls on my webform that allows the user to enter any numbers from 1 to 25 in any order. However, I would like to sort those numbers from least to greatest before sending them to the database. How can accomplish this task? Thanks!
15
2251
by: JIM.H. | last post by:
Hello, Can I send a dataset as a parameter into stored procedure and import data to a table in the stored procedure? Thanks, Jim.
9
47207
by: Nikolay Petrov | last post by:
How to fill DataSet from stored procedure?
5
3629
by: Dennis | last post by:
Hi I'm trying to alter my stored procedure to take a parameter for the Database Name, but as usual the syntax is killing me. Thanks for any help Dennis '--------------------------------------------------------------------------­-------------------------------- Before - This Works without a paramater '--------------------------------------------------------------------------­--------------------------------
4
3380
by: aCe | last post by:
hi all, i need to convert these simple PHP code into stored procedure : <?php $result = mssql_query( "SELECT whid, whcode FROM warehouse" ); while( $wh = mssql_fetch_object( $result ) ) { $result = mssql_query( "SELECT plid, nopl FROM packlist WHERE whid = '" . $wh->whid . "'"; while( $pl = mssql_fetch_object( $result ) ) {
3
2377
by: ckauvar | last post by:
The PHP below calls a stored procedure in a MSSQL database when I am using SQL in a Windows environment. I've recently switched to a UNIX environment and am now using ODBC (via FreeTDS) to connect to the MSSQL database. I need to rewrite the PHP below to use the odbc_connect terminology instead of the mssql_connect terminology. Can anyone help me with this? I know the changes are probably simple, but I don't even know where to start....
2
7544
Plater
by: Plater | last post by:
So this is kind of an odd request. I want to be able to return a small "hardcoded" dataset from a stored procedure. Is that even possible? I want for example a "GetAvailableTypes" store procedure to return like: boat car truck suv
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.