Dim con as new OledbConnection
con = new OledbConnection (constring)
con.open()

Dim cmd as new OledbCommand
cmd = new OledbCommand("Delete Query")
cmd.ExecuteNonQuery()

cmd.Dispose()
con.close()

I tried this code and it is throwing an exception that connection property has not been initialized!!!
giving error in this statement

cmd.ExecuteNonQuery()

try this

Dim con as new OledbConnection
con = new OledbConnection (constring)
con.open()

Dim cmd as new OledbCommand
cmd = new OledbCommand("Delete Query",con)
cmd.ExecuteNonQuery()

cmd.Dispose()
con.close()

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    Try
        oCmdOleDb = New OleDbCommand("Delete from table1")
        oConnOleDb = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\database1.mdb")
        oConnOleDb.Open()



        If (oCmdOleDb.ExecuteNonQuery > 0) Then
            StatusStrip1.Items(0).Text = ("records deleted from the table")
        End If

    Catch ex As Exception
        MsgBox(ex.Message.ToString(), MsgBoxStyle.Information)



    Finally

        oConnOleDb.Close()
    End Try


End Sub

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Try
oConnOleDb = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\database1.mdb")
oConnOleDb.Open()
oCmdOleDb = New OleDbCommand("Delete from table1",oConnOleDb)


If (oCmdOleDb.ExecuteNonQuery > 0) Then
StatusStrip1.Items(0).Text = ("records deleted from the table")
End If

Catch ex As Exception
MsgBox(ex.Message.ToString(), MsgBoxStyle.Information)

Finally
oConnOleDb.Close()
End Try

End Sub

This question has already been answered. Start a new discussion instead.