1
votes

I'm very new to ASP and working on a project using ASP and not ASP.NET.

I have a small application in which after login, user can upload .xls file, then the record from this excel file is inserted into an Access database.

My sample project files are working fine i.e file uploaded and inserted to Access. My problem is that I want to insert data from that Excel file into Access with the unique user_id of the particular user, because many users can insert Excel files to same table. So that when user click on "view records", he should see only his records, not the records of others.

And another thing is figuring out how to save files with unique file names corresponding to the logged in user to avoid duplication of files.

This is the URL from which I got the code for using files for upload and inserting Excel data into Access: http://shotdev.com/asp/asp-excel/asp-upload-excel-import-to-database/.

1
It should be a fairly straight-forward amend to add an integer value (the UserID) to the code which is inserting in to the database. Could you post the code you have so far.Rory McCrossan
pls again check i have uploaded codedasad_ahmad
The answer to your question is below. I modified the code you provided and included the userid.webb

1 Answers

-1
votes

If you have a login page for the users then store the userid in a session variable and then when the user uploads files add the session variable to the insert routine of the uploaded file.

an example of your tables would be.

tblUsers (userid, myuser, mypasscode )

tblfiles (fileid, filename, filetitle, userid)

For your case, iv'e added the userid into the table columns, and also added the session variable for the logged in user.

For  i = 2 To 5
If Trim(xlSheet1.Cells.Item(i,1)) <> "" Then  
strSQL = ""  
strSQL = strSQL &"INSERT INTO customer2 "  
strSQL = strSQL &"(userid, CustomerID,Name,Email,CountryCode,Budget,Used) "  
strSQL = strSQL &"VALUES "  
strSQL = strSQL &"('& sessionvariable &', "&xlSheet1.Cells.Item(i,1)&"','"&xlSheet1.Cells.Item(i,2)&"',     '"&xlSheet1.Cells.Item(i,3)&"' "  
strSQL = strSQL &",'"&xlSheet1.Cells.Item(i,4)&"','"&xlSheet1.Cells.Item(i,5)&"',     '"&xlSheet1.Cells.Item(i,6)&"') "  
Set objExec = Conn.Execute(strSQL)  
Set objExec = Nothing  
End IF  
Next