0

I was wondering whether someone can provide me with some assistance on how I can import CSV data using a text box through a web form to import the data into a SQL database using a stored procedure?

For example, I would like to copy and paste the CSV data into a web form and when I hit submit call up a stored procedure which then does the import into the SQL table.

I have about 5 columns and about 30 rows to import at a time.

I don't want a file upload facility, etc and the user does not have access to the server to conduct the bulk import themselves.

Thank you

GlenCloncurry
  • 457
  • 3
  • 5
  • 15
  • What technology are you using for the website? I know that .net technologies supports the use of table valued parameters (so you don't have to deal with splitting the string in the database), and I'm guessing some other technologies supports that as well. – Zohar Peled Jul 21 '16 at 04:37
  • Hi Zohar, I'm running Kendo UI with .net on the background but I don't have access to the system. The only way I can write data to the system is using a stored procedure. – GlenCloncurry Jul 21 '16 at 04:57
  • With all these restrictions you can receive `.csv` from textbox and then read line-by-line (first line may be special). You can create `Systen.Data.DataTable` then add columns from 1st line and fill data from lines. then use `WriteXml` and send the resulting string to SP. In the SP use sql-xml methods. The closest example is here: https://msdn.microsoft.com/en-us/library/system.data.datatable.writexml(v=vs.110).aspx – Alex Kudryashev Jul 21 '16 at 05:18
  • Then instead of sending csv data to sql server, use a table valued parameter. you can read about it [here](https://msdn.microsoft.com/en-us/library/bb510489.aspx) and [there](http://stackoverflow.com/questions/31965233/adding-multiple-parameterized-variables-to-a-database-in-c-sharp/31965525#31965525). – Zohar Peled Jul 21 '16 at 05:20

0 Answers0