?
Solved

bulk insert from asp.net textarea

Posted on 2009-07-08
12
Medium Priority
?
551 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 2000 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

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!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 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