473,467 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

import xml data in sql server through asp.net

2 New Member
DECLARE @results table (result xml)
DECLARE @xml XML
SELECT @xml =CONVERT(XML, bulkcolumn, 2)
FROM OPENROWSET(BULK 'D:\xmlfile\abc\Technicle1021012.xml', SINGLE_BLOB)
AS x
select @xml



i want to stor this xml data in our sql database
so help me
Feb 2 '12 #1

✓ answered by PsychoCoder

If you're wanting to do this in a .NET language then take that SQL code, make a stored procedure then call it from code. Here's an example of what I'm describing:

Expand|Select|Wrap|Line Numbers
  1. SET ANSI_NULLS ON
  2. GO
  3. SET QUOTED_IDENTIFIER ON
  4. GO
  5. CREATE PROCEDURE ImportXML 
  6.     -- Add the parameters for the stored procedure here
  7.     @FileContents VARCHAR(4000)
  8. AS
  9. BEGIN
  10.     SET NOCOUNT ON;
  11.     DECLARE @results table (result xml)
  12.     DECLARE @xml XML
  13.     SELECT @xml =CONVERT(XML, bulkcolumn, 2)
  14.     FROM OPENROWSET(BULK @FileContents, SINGLE_BLOB) 
  15.     AS x
  16.     select @xml
  17. END
  18. GO
  19.  
And the code for executing it

Expand|Select|Wrap|Line Numbers
  1. public void ImportSql()
  2. {
  3.     SqlConnection conn = new SqlConnection("YourConnectionString");
  4.     SqlCommand cmd = new SqlCommand();
  5.     cmd.Connection = conn;
  6.     cmd.CommandText = "ImportXML";
  7.     cmd.CommandType = CommandType.StoredProcedure;
  8.  
  9.     cmd.Parameters.AddWithValue("@FileContents", "D:\xmlfile\abc\Technicle1021012.xml");
  10.     cmd.ExecuteNonQuery();
  11. }
  12.  
NOTE: There may be some changes that need to be made, I wrote this example in Notepad but it should get you started down the right path.

1 3466
PsychoCoder
465 Recognized Expert Moderator Contributor
If you're wanting to do this in a .NET language then take that SQL code, make a stored procedure then call it from code. Here's an example of what I'm describing:

Expand|Select|Wrap|Line Numbers
  1. SET ANSI_NULLS ON
  2. GO
  3. SET QUOTED_IDENTIFIER ON
  4. GO
  5. CREATE PROCEDURE ImportXML 
  6.     -- Add the parameters for the stored procedure here
  7.     @FileContents VARCHAR(4000)
  8. AS
  9. BEGIN
  10.     SET NOCOUNT ON;
  11.     DECLARE @results table (result xml)
  12.     DECLARE @xml XML
  13.     SELECT @xml =CONVERT(XML, bulkcolumn, 2)
  14.     FROM OPENROWSET(BULK @FileContents, SINGLE_BLOB) 
  15.     AS x
  16.     select @xml
  17. END
  18. GO
  19.  
And the code for executing it

Expand|Select|Wrap|Line Numbers
  1. public void ImportSql()
  2. {
  3.     SqlConnection conn = new SqlConnection("YourConnectionString");
  4.     SqlCommand cmd = new SqlCommand();
  5.     cmd.Connection = conn;
  6.     cmd.CommandText = "ImportXML";
  7.     cmd.CommandType = CommandType.StoredProcedure;
  8.  
  9.     cmd.Parameters.AddWithValue("@FileContents", "D:\xmlfile\abc\Technicle1021012.xml");
  10.     cmd.ExecuteNonQuery();
  11. }
  12.  
NOTE: There may be some changes that need to be made, I wrote this example in Notepad but it should get you started down the right path.
Feb 2 '12 #2

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

Similar topics

3
by: Schultz | last post by:
I would like to know if it is possible to import data from MS Excel 2000 to a dataset using asp.net. The excel file would need to be uploaded to the server from a web page first, before the loaded...
1
by: Deep | last post by:
i whould u like to import data from sql server database into excel sheet using vb.net
2
by: Purvi | last post by:
How to import data from excel sheet to ms sql table the data in the excel is the one which is exported from oracle, few data fields of the ms sql server are of int type and few are of varchar, how...
0
by: sadiquekhan | last post by:
How to import data from excel sheet to SQL server , in java programming.
2
by: rmsterling | last post by:
All, Subject: SQL Server 2005 - How do I import data from an Oracle Data Pump file? Tried looking in the SQL help for this and it's not very forthcoming on how you do this. How do I...
0
by: kelvenng | last post by:
Hi all hope some one can help me solve my problem. Actually I want import data from excel to my MYSQL server by using VB6 I facing the problem on my coding and system show me the error. below is...
1
by: Amit | last post by:
Hello , Is there any way i can import data from datagrid to sqlserver. please advise . thanks & Regards
6
by: AccessHunter | last post by:
Hi, I am trying to import data from an Access 2003 database table 'Cases' to the table 9dbo.Cases) in SQL Sever database and its giving me the following error. Could someone please explain what...
4
by: gauthambr83 | last post by:
Hi all, I want to know how to import SQL Server(2005) data into a DAT file. Can anyone help me on this.
9
by: a | last post by:
Dear friends I want import data from CSV file to mdb file How can I do that in vb.net?
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.