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 Code | Item 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...
Munesh SharmaPosted Jun 29, 2015, 5:24 AM
Jonathan SterlingPosted Jun 29, 2015, 5:06 AM
Ahmed JSPosted Nov 10, 2014, 10:00 AM
http://sqlneed.blogspot.com/2013/06/Import-Data-from-Excel-to-SQL-C-sharp.html
Riddhi ValechaPosted Oct 21, 2014, 3:31 AM
The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data.
Riddhi ValechaPosted Oct 16, 2014, 4:13 AM
I implemented your method.
But, only first row got inserted.
Please provide the sample code if you have...
Thanks a lot in advance...
Please provide it as soon as possible, it is urgent..
Riddhi ValechaPosted Oct 14, 2014, 1:39 AM
Thanks a lot...
Please provide the sample code if possible.
Thanks a ton in advance.
Abhishek KumarPosted Oct 13, 2014, 7:39 AM
Below is steps you need to follow.
On button click after Login
Validation for xls, xlsx, or csv using below client site code
<script type ="text/javascript">
var validFilesTypes=["xlsx", "csv", "xls"];
function ValidateUpload()
{
var file = document.getElementById("<%=FileUpload1.ClientID%>");
var label = document.getElementById("<%=Label1.ClientID%>");
var path = file.value;
var ext=path.substring(path.lastIndexOf(".")+1,path.length).toLowerCase();
var isValidFile = false;
for (var i=0; i
{
if (ext==validFilesTypes[i])
{
isValidFile=true;
break;
}
}
if (!isValidFile)
{
label.style.color="red";
label.innerHTML="Invalid File. Please upload a File with" +
" extension:\n\n"+validFilesTypes.join(", ");
}
return isValidFile;
}
script>
Read the data from fiel to data set
use below link
http://www.codeproject.com/Tips/300639/Import-Data-from-excel-to-SQL-server-using-Csharp
Then Write a code to check the SerialNumber from database
Then
do
Update
else
Insert
Hope these steps will help.
Let me know if you want sample application or code for this.
Abhishek