473,395 Members | 1,464 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,395 software developers and data experts.

Pass XML file to SQL stored procedure

17
I Wrote a stored procedure in SQL Server:

CREATE PROCEDURE InsertXML2 @xmlFile varchar(2000) AS
DECLARE @iTree int
SELECT *
FROM OPENXML (@iTree, 'n:Registration/nefaultEnrolment',3)
WITH (
....
)
EXEC sp_xml_removedocument @iTree
GO

How can I pass the XML file to this stored Procedure in VB.NET?

Thanks a lot
Apr 1 '07 #1
10 14252
iburyak
1,017 Expert 512MB
Do following :


[PHP]
EXEC InsertXML2 'text of XML File here'[/PHP]
Apr 2 '07 #2
iburyak
1,017 Expert 512MB
I don't think your procedure works thou.

But if yes then, sorry.
Apr 2 '07 #3
yingwen
17
It works fine in following code:

CREATE PROCEDURE InsertXML AS
DECLARE @iTree int
DECLARE @xmlFile varchar(2000)
SET @xmlFile='<?xml version="1.0" ?>
<Registration

</Registration>'

--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @iTree OUTPUT, @xmlFile,
'<root xmlns:n="NZL:govt:IRD:KiwiSaver:B2BInterfaces:Regi sterMember:v1.0"
xmlns:xAL="urn:oasis:names:tc:ciq:xal:3"
xmlns:xNL="urn:oasis:names:tc:ciq:xnl:3"
xmlns:xPIL="urn:oasis:names:tc:ciq:xpil:3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="NZL:govt:IRD:KiwiSaver:B2BInte rfaces:RegisterMember:v1.0 ../RegisterMember.xsd"/>'

-- Execute a SELECT statement that uses the OPENXML rowset provider.
SELECT *
FROM OPENXML (@iTree, 'n:Registration/n:DefaultEnrolment',3)
WITH (
DateSent datetime './@DateSent',
Number decimal 'n:Scheme/@Number',
ActiveType char(2) 'n:Scheme/@ActiveType',
AddressLine1 varchar(30) 'child::n:MemberAddress/xAL:FreeTextAddress/xAL:AddressLine[position() = 1]',
AddressLine2 varchar(30) 'child::n:MemberAddress/xAL:FreeTextAddress/xAL:AddressLine[position() = 2]',

BirthDateTime datetime 'xPIL:BirthInfo/@xPIL:BirthDateTime',
EmployerName varchar(20) 'n:Employers/n:Employer/n:OrganizationName/xNL:NameElement/text()'
)
EXEC sp_xml_removedocument @iTree
GO

How can I pass the xml file into
CREATE PROCEDURE InsertXML @fileName varchar(2000) AS

in VB.NET?


Thanks in advance
Apr 2 '07 #4
iburyak
1,017 Expert 512MB
What server do you use?
Apr 2 '07 #5
iburyak
1,017 Expert 512MB
It should be something like this:

1. Create proc which accepts parameter as a varchar:

[PHP]CREATE PROCEDURE InsertXML
@xmlFile varchar(8000)
AS
DECLARE @iTree int

............[/PHP]


2. Call procedure from vb.net

[PHP]object.execute "InsertXML '<?xml version="1.0" ?>
<Registration>

</Registration>'"[/PHP]


You can store text of an XML File in a variable first

[PHP]object.execute "InsertXML '" & XML_Variable_Here & "'" [/PHP]


Good Luck.
Apr 2 '07 #6
yingwen
17
What server do you use?

I am using SQL Server 2000
Apr 2 '07 #7
yingwen
17
Thank you very much for your quick responses.

I have another problem here. How can I turn a XML file into a xml string.

I have tried streamreader, xmltextreader, the out put results only give me the text() part of xml file(all xml tags are not included).

In other words How can I convert xml file into
A string =
"<?xml version="1.0"?><Registration
xmlns="NZL:govt:IRD:KiwiSaver:B2BInterfaces:Regist erMember:v1.0"
xmlns:xAL="urn:oasis:names:tc:ciq:xal:3"
xmlns:xNL="urn:oasis:names:tc:ciq:xnl:3
</Registration>"

Thank you very much.
Apr 2 '07 #8
iburyak
1,017 Expert 512MB
Just open file like any text file, don't worry that it is an XML and get entire text into a variable.

If you use Server 2000 you have a danger to overflow maximum size of a character variable which is 8000. I managed to work around this problem but it requires some programming skills on your side.

SQL doesn't really care of any name spaces as long as it is well formed document with root node and children nodes.

I have to go now. Will talk tomorrow if you need more help.

Have a good day.
Apr 2 '07 #9
yingwen
17
Thank you very much for your reply.


I have tried streamreader, xmldocument, xmlreader, but they only read the text part of xml.

E.g. for a simple xml file:

<Root>
<book>title1</book>
</Root>

The output is only "title1", but I want the whole thing.

The problem is how can I read (more complicated than above) entire xml file into a string?

Thank you.
Apr 2 '07 #10
iburyak
1,017 Expert 512MB
This code works fine:

[PHP]Dim sr As StreamReader = File.OpenText("C:\test.xml")
Dim str As String = sr.ReadToEnd()[/PHP]
Apr 3 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jeff Thur | last post by:
I am running a SQL Stored Procedure that will give the user a count of how many records are in the database as per certain criteria. I'm using the Execute Scalar Method. I have no problem passing...
0
by: Chan | last post by:
Hi, I am trying to send set of rows from my c# web service to Oracle stored procedure. I think I can get this done using OpenXML in SQL Server. How to implement this in Oracle Stored...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
0
by: Chan | last post by:
Hi, I am trying to send set of rows from my c# web service to Oracle stored procedure. I think I can get this done using OpenXML in SQL Server. How to implement this in Oracle Stored...
4
by: CsharpGuy | last post by:
I took over an web app (C#) were the developer put everything in a has table then called a method to execute a stored procedure, now I'm running into some issues were if I do an update and a NULL...
3
by: Joseph Lu | last post by:
Hi, all I have a stored procedure created in SQL Server like the following lines. // stored proceudre code starts here CREATE PROCEDURE sp_insertdata @strdata varchar(250) , @rsult BIT...
1
by: mjkelly | last post by:
Hi, I have a stored procedure written in java in an Oracle 10g db. This sp takes a java.lang.String as input, creates a file on disk and writes the string contents to it and inserts the filename...
5
by: yingwen | last post by:
I Wrote a stored procedure in SQL Server: CREATE PROCEDURE InsertXML2 @xmlFile varchar(2000) AS DECLARE @iTree int SELECT * FROM OPENXML (@iTree, 'n:Registration/n:DefaultEnrolment',3) ...
1
by: sreedivya | last post by:
Hi All I am trying to create crystal reports. In this concern i have created a command which execute a stored procedure. This stored procedure takes three parameters which in turn i want to pass it...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...
0
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,...
0
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...
0
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...

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.