lew26
03-12-2006, 06:36 AM
hello,
I been working on this project for weeks now i can't seem to extract the date from an excel file using ADO.Net here is the code below. What i would like to accomplish is i would like to gather all the values from each row with the excel file and insert them into an array and a listbox. Then basically from there i can work with the array in other modules. The excel file contain three columns (Name, Phone, Email).
Every bit of help will be greatly appreciated.
Private Sub frmBulkEmailer_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
'Dim da As OleDb.OleDbDataAdapter = New Data.OleDb.OleDbDataAdapter
Dim dr As OleDb.OleDbDataReader
'Dim dp As OleDb.OleDbParameter = New Data.OleDb.OleDbParameter
'========================================
' oledb select
'========================================
Dim xdb As DBmConnect.ExcelmConn
Dim xlConn As String
xdb = New DBmConnect.ExcelmConn
xlConn = xdb.oledbExcelStandard("\xldoc.xls", "c:\docs")
'Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(xlConn)
Dim command As OleDb.OleDbCommand
Dim strSQL As String
Dim mName, mPhone, mEmail As String
Dim lstCustomers As ListBox = New ListBox
Try
'conn.Open()
'command.Connection = conn
'-- Create the SQL String
strSQL = "Select * FROM [sheet2]"
command = New OleDbCommand
With command
'-- Set up the connection of the command and the command text
.Connection = _
New OleDb.OleDbConnection(xlConn)
.Connection.Open()
.CommandText = strSQL
'-- Set up the data reader instance
dr = .ExecuteReader(CommandBehavior.SequentialAccess)
End With
'-- Add the items to the list box.
With Me.lbData
.Items.Clear()
.BeginUpdate()
Do While dr.Read
.Items.Add(dr.Item("Name"))
Loop
.EndUpdate()
End With
'command.CommandText = "SELECT Name FROM [sheet2] as @mName"
'command.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
'conn.Close()
End Try
End Sub
I been working on this project for weeks now i can't seem to extract the date from an excel file using ADO.Net here is the code below. What i would like to accomplish is i would like to gather all the values from each row with the excel file and insert them into an array and a listbox. Then basically from there i can work with the array in other modules. The excel file contain three columns (Name, Phone, Email).
Every bit of help will be greatly appreciated.
Private Sub frmBulkEmailer_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
'Dim da As OleDb.OleDbDataAdapter = New Data.OleDb.OleDbDataAdapter
Dim dr As OleDb.OleDbDataReader
'Dim dp As OleDb.OleDbParameter = New Data.OleDb.OleDbParameter
'========================================
' oledb select
'========================================
Dim xdb As DBmConnect.ExcelmConn
Dim xlConn As String
xdb = New DBmConnect.ExcelmConn
xlConn = xdb.oledbExcelStandard("\xldoc.xls", "c:\docs")
'Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(xlConn)
Dim command As OleDb.OleDbCommand
Dim strSQL As String
Dim mName, mPhone, mEmail As String
Dim lstCustomers As ListBox = New ListBox
Try
'conn.Open()
'command.Connection = conn
'-- Create the SQL String
strSQL = "Select * FROM [sheet2]"
command = New OleDbCommand
With command
'-- Set up the connection of the command and the command text
.Connection = _
New OleDb.OleDbConnection(xlConn)
.Connection.Open()
.CommandText = strSQL
'-- Set up the data reader instance
dr = .ExecuteReader(CommandBehavior.SequentialAccess)
End With
'-- Add the items to the list box.
With Me.lbData
.Items.Clear()
.BeginUpdate()
Do While dr.Read
.Items.Add(dr.Item("Name"))
Loop
.EndUpdate()
End With
'command.CommandText = "SELECT Name FROM [sheet2] as @mName"
'command.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
'conn.Close()
End Try
End Sub