I am having trouble with dropping a temp table. I was using it so many times in other projects but this time it went bad.
The only thing different now is that I referred a string value from the main form to another form.The other form populates a dgv based on the string value being accessed from the main form.
The drop table statement is placed at the form_load event of the other form.
Now the drop table procedure works fine when the form is closed and reopened with the condition of no record being passed to the temp table. But if at least one record is stored in the temp table and when the form is closed and reopened instead of dropping the table it pops a message saying 'temptable already exists'. Any help would be appreciated.Thank you
Here's the code that I've used:
This is a code i used in the main form under a toolstrip button
Dim node As TreeNode node = New TreeNode node = TreeView3.SelectedNode If node Is Nothing Then MsgBox("Select a location from the list", MsgBoxStyle.Exclamation, "Payroll") TreeView3.ExpandAll() Exit Sub ElseIf node.Level <> 1 Then MsgBox("Select a location from the Locations list", MsgBoxStyle.Exclamation, "Payroll") TreeView3.ExpandAll() Exit Sub Else frmNewPerdiem.Show() End If
These are codes i used in the other form:
Private Sub frmNewPerdiem_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim qry2 As String = "SELECT * INTO temppd FROM tblPerDiem WHERE [monthIssued] AND [employeeID] IS NULL" DroptempTable() ExecSQL(qry2) LoadEmployees() End Sub Public Sub LoadEmployees() conn = New OleDb.OleDbConnection(sconnString) conn.Open() cmd.Connection = conn cmd.CommandType = CommandType.Text Dim empLocation As String = String.Empty empLocation = frmMain.pdlocation 'This is where i referred the value of the string from the main form cmd.CommandText = "sql statement" da.SelectCommand = cmd dtresult = New DataTable da.Fill(dtresult) Me.employeeDataGridView.DataSource = dtresult da.Dispose() cmd.Dispose() conn.Close() End Sub Private Sub DroptempTable() On Error GoTo ErrorHandler 'conn = New OleDb.OleDbConnection(sconnString) 'conn.Open() 'cmd.Connection = conn 'cmd.CommandType = CommandType.Text Dim str As String = "DROP TABLE temppd" ExecSQL(str) 'cmd.ExecuteNonQuery() 'cmd.Dispose() 'conn.Close() ErrorHandler: If Err.Number = 7874 Then Resume Next End If End Sub