Problem in Importing data from excel to database,please help me
-
'Getting a file path If Not FILE1.PostedFile.FileName = "" Then FilePath = FILE1.PostedFile.FileName End If 'Excel Work Sheet Database Connection MyConnection = New System.Data.OleDb.OleDbConnection( _ "provider=Microsoft.Jet.OLEDB.4.0; " & _ "data source=" & FilePath & "; " & _ "Extended Properties=Excel 8.0;") 'Select the data from Sheet1 of the workbook. 'FilePath comes as c:\export\mydata.xls 'now i am going to retrive the "mydata" name only because of while iam storing the excel file,it is being stored as mydata.xls and at the same time sheet name also being changed as mydata whenever i am going to retrieve the data, i have to specify the sheet name for that i am doing the below code, but i am getting an error, it is alreday open by another user or some other error is displayed Dim f As Array f = Split(FilePath, "\") Dim k As Integer = f.Length Dim str As String = f(k - 1) Dim filename As String = str.Substring(0, str.LastIndexOf(".")) '' Select the data from Sheet1 of the workbook. MyCommand = New System.Data.OleDb.OleDbDataAdapter( _ "select * from [" & filename & "$]", MyConnection) DS = New System.Data.DataSet 'DataSet MyCommand.Fill(DS) 'Filling The dataset please help me, when iam going to export the data from database to excel, it is storing it as c1.xls(we give) and sheet1 name is also stored as c1.xls when i am going to retrieve the data from it, it is giving an error(as above said) please help me regards kishore go2kish@yahoo.com kishore