Solved

bulk insert from asp.net textarea

Posted on 2009-07-08
12
549 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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