object reference not released when using ADO.NET

P

pshen

Hi Experts,

I am using ado.net to export data to excel 2002 with oledb like the
following (this a sample code from MSDN) --

Dim sConnectionString As String
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sSampleFolder & _
"Book7.xls;Extended Properties=Excel 8.0;"
Dim objConn As New
System.Data.OleDb.OleDbConnection(sConnectionString)
objConn.Open()

'Add two records to the table named 'MyTable'.
Dim objCmd As New System.Data.OleDb.OleDbCommand()
objCmd.Connection = objConn
objCmd.CommandText = "Insert into [Sheet1$] (FirstName, LastName)" & _
" values ('Bill', 'Brown')"
objCmd.ExecuteNonQuery()
objCmd.CommandText = "Insert into [Sheet1$] (FirstName, LastName)" & _
" values ('Joe', 'Thomas')"
objCmd.ExecuteNonQuery()

'Close the connection.
objConn.Close()
objConn.Dispose()
objCmd = Nothing
objConn = Nothing
GC.Collect()

I have two problems:

1) when the excel program is closed, there is still a reference to Excel
listed under "Task Manager". What else do I need to do to clear that
reference?
2) It seems there is no control to which row the first data set will be
inserted. Data will be keeping inserted to the next row. Even you save the
workbook and reoped, the new data will be inserted to the next empty row. Is
there any way to tell the program the starting row?


Thanks for your kind help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top