473,503 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing an Excel sheet into a SQL dB using VB.NET remotely

1 New Member
Hello,

My code works just fine when I run it locally, but when I put it up on a test server and try to import an excel file which resides on my local machine I get this error:

'C:\Documents and Settings\rflint\Desktop\Import Folder\InventoryImportTemplate.xls' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

Here is the Upload function:

Protected Sub ButtonUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim ExcelFilePath As String = FileUpload1.PostedFile.FileName
Dim ExcelFileName As String = FileUpload1.FileName
If IsPostBack Then
Try
Dim conn As OleDbConnection = Nothing
Dim excelConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ExcelFilePath & ";Extended Properties=Excel 8.0;;Persist Security Info=False"

' Create Connection to Excel Workbook
Using connection As New OleDbConnection(excelConnectionString)
Dim command As New OleDbCommand("Select * from [Sheet1$]", connection)
connection.Open()

' Create DbDataReader to Data Worksheet
Using dr As OleDbDataReader = command.ExecuteReader()
' SQL Server Connection String
Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrin gs(1).ToString)
myConnection.Open()

' Bulk Copy to SQL Server
Using bulkCopy As New SqlBulkCopy(myConnection)
bulkCopy.DestinationTableName = "ExcelData"
bulkCopy.WriteToServer(dr)
End Using
myConnection.Close()
GetExcelData()
End Using
End Using
Catch ex As Exception
Response.Write(ex.Message)
Finally
End Try
End If
End Sub
Oct 29 '07 #1
0 1358

Sign in to post your reply or Sign up for a free account.

Similar topics

9
4016
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
7
3026
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
3
25021
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown....
9
3893
by: jillandgordon | last post by:
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I get to the lst step and am told that it was not imported due to an error. ...
1
2287
by: Vivek | last post by:
Hi all, I am trying to import data from an excel sheet to MSSQL server 2000 using a web application (C#). Since I have to validate the data in the excel sheet, the approach i have used is to get...
3
8910
by: Conrad F | last post by:
Hello All, I know how to import a specific named excel sheet into a datagrid using ADO.NET by setting up a JET connection and then SELECTing data from the sheet. However, for a real world...
0
2988
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from...
0
767
by: DrewYK | last post by:
I have the project that may never end in front of me. I am creating a routine that will take SpreadSheets from Excel and bring them into Access. I am not using any "DoCmd"s because the goal...
4
7333
by: Harshe | last post by:
hello all, I am trying to code, but i am just stuck after importing one sheet. so here is the gist of what i need help with. In a workbook at the start of the year (january) i will have 4...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.