G
Guest
I am using an oldDBconnection to do a sql insert and update to a spreadsheet.
If the Speadsheet is open in excel when the .net program updates the
spreadsheet then excel.exe lingers in task manager.
Can anyone suggest what is the fix? Code works fine if spreadsheet is not
open.
Thanks very fustrating excel.exe lingering.
Here is code snippet:
Dim conn As OleDbConnection
Try
conn = New OleDbConnection(szConnect)
conn.Open()
cmd = New OleDbCommand
cmd.Connection = conn
' test if there
szSQL = "Select * from " & strSheet & " WHERE " &
strWhereCol & "='" & strSymbol & "'"
cmd.CommandText = szSQL
oledbReader = cmd.ExecuteReader()
If (oledbReader.HasRows) Then
' can do UPDATE
szSQL = "UPDATE " & strSheet & " SET " & strFieldName &
"='" & strDateIn & "' WHERE " & _
strWhereCol & "='" & strSymbol & "'"
Else
' try and insert
szSQL = "INSERT INTO " & strSheet & " (" & strWhereCol &
"," & strFieldName & ") VALUES('" & strSymbol & _
"','" & strDateIn & "')"
End If
' now close datareader
oledbReader.Close()
cmd.CommandText = szSQL
cmd.ExecuteNonQuery()
cmd.Connection.Close()
conn.Close()
conn.Dispose()
cmd.Dispose()
If the Speadsheet is open in excel when the .net program updates the
spreadsheet then excel.exe lingers in task manager.
Can anyone suggest what is the fix? Code works fine if spreadsheet is not
open.
Thanks very fustrating excel.exe lingering.
Here is code snippet:
Dim conn As OleDbConnection
Try
conn = New OleDbConnection(szConnect)
conn.Open()
cmd = New OleDbCommand
cmd.Connection = conn
' test if there
szSQL = "Select * from " & strSheet & " WHERE " &
strWhereCol & "='" & strSymbol & "'"
cmd.CommandText = szSQL
oledbReader = cmd.ExecuteReader()
If (oledbReader.HasRows) Then
' can do UPDATE
szSQL = "UPDATE " & strSheet & " SET " & strFieldName &
"='" & strDateIn & "' WHERE " & _
strWhereCol & "='" & strSymbol & "'"
Else
' try and insert
szSQL = "INSERT INTO " & strSheet & " (" & strWhereCol &
"," & strFieldName & ") VALUES('" & strSymbol & _
"','" & strDateIn & "')"
End If
' now close datareader
oledbReader.Close()
cmd.CommandText = szSQL
cmd.ExecuteNonQuery()
cmd.Connection.Close()
conn.Close()
conn.Dispose()
cmd.Dispose()