View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
pshen pshen is offline
external usenet poster
 
Posts: 4
Default object reference not released when using ADO.NET

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(sConnectionStrin g)
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

--
jshen