Click here to Skip to main content
15,400,282 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
i want upload only .csv format files in my web page and as soon as i click on Update button it will automatically create table with columns
here
file name= table name and
first row of the file (headings)= columns of the table

how to write the code for it in MS SQL server. .
Posted

1 solution

First you need to know how to execute SQL code.

The following describes that how to execute SQL statements from c#.

http://msdn.microsoft.com/en-US/library/0k7hxwz6(v=vs.80).aspx[^]

Then you need to read in the CSV to get the structure of the file. One such reader is available on CodeProject :-)

A Fast CSV Reader[^]

Next you need to construct an SQL statement which creates the table. The following explains the CREATE TABLE command is SQL.

http://www.w3schools.com/sql/sql_create_table.asp[^]

Then you need to execute this command against SQL.

Then you need to read the data in with your CSV reader and insert into the new table.

The following is information on the INSERT command.

http://www.w3schools.com/sql/sql_insert.asp[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900