954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

deleting the records of the MS access table using VB.NET

I have to delete the records in a ms access table using vb.net when i click on a button.

kritiohri
Newbie Poster
24 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

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

reena12
Light Poster
32 posts since Oct 2008
Reputation Points: 12
Solved Threads: 4
 

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

cmd.ExecuteNonQuery()
kritiohri
Newbie Poster
24 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

Hi,
pls post your code

reena12
Light Poster
32 posts since Oct 2008
Reputation Points: 12
Solved Threads: 4
 

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

reena12
Light Poster
32 posts since Oct 2008
Reputation Points: 12
Solved Threads: 4
 

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

[/code]

kritiohri
Newbie Poster
24 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

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

reena12
Light Poster
32 posts since Oct 2008
Reputation Points: 12
Solved Threads: 4
 

Thanks a ton...I solved the problem

kritiohri
Newbie Poster
24 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You