Solved

bulk insert from asp.net textarea

Posted on 2009-07-08
12
538 Views
Last Modified: 2012-05-07
Is there a way to do a bulk insert from a asp.net textarea instead of a file?
0
Comment
Question by:mattegol
  • 6
  • 6
12 Comments
 
LVL 15

Expert Comment

by:spprivate
ID: 24806977
Assuming you are using Oracle as database you can define the field as a clob in back end
Here is an hands on on inserting data to CLOB

http://www.codeproject.com/KB/database/C__and_Oracle.aspx
0
 

Author Comment

by:mattegol
ID: 24807123
I'm using mssql 2000
0
 

Author Comment

by:mattegol
ID: 24807460
To explain it better:

I was thinking to provide a textarea for the user to copy and paste data from a text file and then my web page will read line by line to store the data into columns firtsname, lastname, email in the database

Example data:
John,Smith,john@email.com
Clark,Cent,clark@email.com
Jessica,Anderson,jessica@email.com

0
 
LVL 15

Expert Comment

by:spprivate
ID: 24807520
What is the data size.
Normally varchar can store upto 8000 char
0
 

Author Comment

by:mattegol
ID: 24807616
The data size will be different each time, if the datasize is more then 8000 chars then they should be able to do a second insert right?...

Lets say the most common size is less then 8000.
0
 
LVL 15

Expert Comment

by:spprivate
ID: 24807624
Here is a storedprocedure to help this
http://itknowledgeexchange.techtarget.com/itanswers/string-value-to-table-column/
What you need to do is
once user pastes the data,read that in c# and look for carriage returns as first delimiter
Once you have that then create a similar procedure as in the example to insert one record at a time.
The other way to do is to create an XML out of the data and send that XML as a input to the sql procedure
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 15

Expert Comment

by:spprivate
ID: 24807647

Step 1 Get the value in string builder object
Step 2 parse for carriage returns and store that substrings in a string array with "," separated.
Step 3 Pass that array elements one by one as input to the procedure
0
 

Author Comment

by:mattegol
ID: 24808011
Will look that up tomorrow, it's late in the evening here. Thanks
0
 

Author Comment

by:mattegol
ID: 24811634
I think I will try to create a XML of the data and send that XML as a input to the proc. Would'nt that be a more simple solution?

Is it hard to convert a excel file to XML and then send the XML to the proc?

I'm gonna increase the points to 500
0
 
LVL 15

Expert Comment

by:spprivate
ID: 24816266
Converting to xml is indeed a simple solution.
I will attach a sample procedure for that.

From excel, load a dataset with excel as the source and then use ds.writexml method to get the xml from it.
Then send this to procedure
0
 
LVL 15

Accepted Solution

by:
spprivate earned 500 total points
ID: 24816650
I have given the stored procedure I use to insert records using xml.
Note that each node will directly correspond to the column name in the database table
CREATE Procedure [dbo].[SP_Insert_XML_Details]

(

@Ref_Details varchar(8000)

)

As

DECLARE @idoc int
 

/*

'<?xml version="1.0" ?>

<ROOT>

<EmployeeId="4" Email="ss@ss.com" Last_Name = "YY" First_Name="XXXX" Address="6005 State" Phone="(503) 
 

666-9831"/>

<Referral Order_Id="4" Referral_Program_Id="TESTID1" Email="ss@ss.com" Last_Name = "Kumar" First_Name="XXXX" Address="6005 State" Phone="(503) 
 

666-9831"/>

<Referral Order_Id="4" Referral_Program_Id="TESTID1" Email="ss@ss.com" Last_Name = "Kumar" First_Name="XXXX" Address="6005 State" Phone="(503) 
 

666-9831"/>

</ROOT>'*/
 

EXEC sp_xml_preparedocument @idoc OUTPUT, @Ref_Details
 

INSERT MAS_ReferralDetails

SELECT * 

FROM OPENXML (@idoc, N'/ROOT/Referral')

          WITH MAS_ReferralDetails
 

EXEC sp_xml_removedocument @idoc
 

GO

Open in new window

0
 

Author Closing Comment

by:mattegol
ID: 31601266
ty
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now