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
Solved

bulk insert from asp.net textarea

Posted on 2009-07-08
12
545 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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