I have problem with my code I need to read from Excel worksheet into dataset
the problem is in this line oleda.Fill(ds). The data adapter should fill
dataSet with data from Excel worksheet but isn't doing so. Below is my
code,thanks
Imports System.Data.Ole Db
Imports System.Data
Imports Oracle.DataAcce ss.Client
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim connString As String = "provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=C:\emplo yeetable.xls;Ex tended Properties=Exce l 8.0;"
' Create the connection object
Dim oledbConn As OleDbConnection = New OleDbConnection (connString)
Try
' Open connection
oledbConn.Open( )
' Create OleDbCommand object and select data from worksheet Sheet1
Dim cmd As OleDbCommand = New OleDbCommand("S ELECT * FROM
[Sheet1$]", oledbConn)
' Create new OleDbDataAdapte r
Dim oleda As OleDbDataAdapte r = New OleDbDataAdapte r()
' Create a DataSet which will hold the data extracted from the
worksheet.
Dim ds As DataSet = New DataSet()
' Fill the DataSet from the data extracted from the worksheet.
oleda.Fill(ds)
Catch
Finally
' Close connection
oledbConn.Close ()
End Try
'1.Create connection object to Oracle database
Dim con As OracleConnectio n = New OracleConnectio n()
Try
'2.Specify connection string
con.ConnectionS tring = ("Data Source=dprod;Us er Id=mtr;
Password=lar777 7")
'3. Open the connection through ODP.NET
con.Open()
Catch ex As Exception
'4.display if any error occurs
MsgBox(ex.Messa ge, Microsoft.Visua lBasic.MsgBoxSt yle.Exclamation ,
"OraScan")
'3.Create command object to perform a query against the database:
Dim cmdQuery As String = "SELECT * FROM employeetable"
' Create the OracleCommand object to work with select
Dim cmd As OracleCommand = New OracleCommand(c mdQuery)
cmd.Connection = con
cmd.CommandType = CommandType.Tex t
' Dispose OracleCommand object
cmd.Dispose()
Finally
' Close and Dispose OracleConnectio n object
con.Close()
con.Dispose()
End Try
End Sub
End Class
the problem is in this line oleda.Fill(ds). The data adapter should fill
dataSet with data from Excel worksheet but isn't doing so. Below is my
code,thanks
Imports System.Data.Ole Db
Imports System.Data
Imports Oracle.DataAcce ss.Client
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim connString As String = "provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=C:\emplo yeetable.xls;Ex tended Properties=Exce l 8.0;"
' Create the connection object
Dim oledbConn As OleDbConnection = New OleDbConnection (connString)
Try
' Open connection
oledbConn.Open( )
' Create OleDbCommand object and select data from worksheet Sheet1
Dim cmd As OleDbCommand = New OleDbCommand("S ELECT * FROM
[Sheet1$]", oledbConn)
' Create new OleDbDataAdapte r
Dim oleda As OleDbDataAdapte r = New OleDbDataAdapte r()
' Create a DataSet which will hold the data extracted from the
worksheet.
Dim ds As DataSet = New DataSet()
' Fill the DataSet from the data extracted from the worksheet.
oleda.Fill(ds)
Catch
Finally
' Close connection
oledbConn.Close ()
End Try
'1.Create connection object to Oracle database
Dim con As OracleConnectio n = New OracleConnectio n()
Try
'2.Specify connection string
con.ConnectionS tring = ("Data Source=dprod;Us er Id=mtr;
Password=lar777 7")
'3. Open the connection through ODP.NET
con.Open()
Catch ex As Exception
'4.display if any error occurs
MsgBox(ex.Messa ge, Microsoft.Visua lBasic.MsgBoxSt yle.Exclamation ,
"OraScan")
'3.Create command object to perform a query against the database:
Dim cmdQuery As String = "SELECT * FROM employeetable"
' Create the OracleCommand object to work with select
Dim cmd As OracleCommand = New OracleCommand(c mdQuery)
cmd.Connection = con
cmd.CommandType = CommandType.Tex t
' Dispose OracleCommand object
cmd.Dispose()
Finally
' Close and Dispose OracleConnectio n object
con.Close()
con.Dispose()
End Try
End Sub
End Class
Comment