Riddhi Valecha

Riddhi Valecha

  • 420
  • 3.3k
  • 412.8k

Insert Data From Excel To SQL Server On Button Click

Oct 13 2014 4:51 AM
Hi all,

I need help in making the following application.

My requirement is -
1. The user have an excel sheet (.xls or .csv) files.
2. The user logs in the system and uploads the file. (Using File Upload button).
3. User clicks "OK" Button.
4. On this button, I have to fire an UPDATE and INSERT Query.
-----------
Queries depend on the data in excel sheet.
-------
The excel sheet is as follows (with 4 columns) -
------------
ID
Serial Number
Item CodeItem Name
Assigned To
1
I1
C1
Mouse
Sunil
2
I2
C2
Keyboard
Ajinkya
3
I3
C3
Keyboard
Aditya

Now, on the button click, the system will fire the query as -
Update tablename set itemcode = Item Code, Item Name = Item Name, Assigned To = Assigned To where Serial No = Serial Number

If Serial Number is not there in the database table, then
Insert into temptable (Serial Number, Item Code, Item Name, Assigned To) values
(Serial Number, Item Code, Item Name, Assigned To)
-----------
Points:-
1. I have to use stored procedures. I cannot write queries in aspx.cs file.
2. File extension can be - xls, xlsx, or csv .

-----------
Please help.
Thanks a lot in advance...

Answers (7)