Hye Buddy,
I am not able to read excel spreadsheet into my sql database. I am using VB Express Edition.
Following is the code which I am using to read excel file datas.
I have Excel 2003 on my system. And I have added Reference Under Add Reference Under COM tab - Microsoft Excel 11.0 Object Library. And Other option I have got is Microsoft Excel 5.0 Object Library.
Private
Sub ImportTempPressData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportTempPressData.Click
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory =
My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter =
"All Microsoft Office Excel Files (*.xls)|*.xls|All Files (*.*)|*.*"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = OpenFileDialog.FileName
'To import data from Excel spreadsheet (RawData.xls) to SQL Server database
cn =
New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" & _
"data source=C:\Data\Rajesh\2-1-4-442\Service Life Software\RawData.XLS;Extended Properties=Excel 8.0;")
''Select the data from Sheet1 of the workbook.
cmd =
New System.Data.OleDb.OleDbDataAdapter("select * from [sheet$1]", cn)
cn.Open()
cmd.Fill(ds)
cn.Close()
cn =
Nothing
End If
End Sub
I would be very happy if some can help me.
Best Regards
Rajesh Kumar