Solved

bulk insert from asp.net textarea

Posted on 2009-07-08
12
544 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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