943,614 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 3806
  • VB.NET RSS
Dec 1st, 2008
0

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

Expand Post »
I have to delete the records in a ms access table using vb.net when i click on a button.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kritiohri is offline Offline
24 posts
since Nov 2008
Dec 1st, 2008
0

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

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()
Reputation Points: 12
Solved Threads: 4
Light Poster
reena12 is offline Offline
32 posts
since Oct 2008
Dec 6th, 2008
0

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

I tried this code and it is throwing an exception that connection property has not been initialized!!!
giving error in this statement
VB.NET Syntax (Toggle Plain Text)
  1. cmd.ExecuteNonQuery()
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kritiohri is offline Offline
24 posts
since Nov 2008
Dec 6th, 2008
0

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

Hi,
pls post your code
Reputation Points: 12
Solved Threads: 4
Light Poster
reena12 is offline Offline
32 posts
since Oct 2008
Dec 6th, 2008
0

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

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()
Reputation Points: 12
Solved Threads: 4
Light Poster
reena12 is offline Offline
32 posts
since Oct 2008
Dec 8th, 2008
0

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

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]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kritiohri is offline Offline
24 posts
since Nov 2008
Dec 8th, 2008
0

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

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
Reputation Points: 12
Solved Threads: 4
Light Poster
reena12 is offline Offline
32 posts
since Oct 2008
Dec 8th, 2008
0

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

Thanks a ton...I solved the problem
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kritiohri is offline Offline
24 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Help with Visual Studio 2008
Next Thread in VB.NET Forum Timeline: can someone help me with saving my data in a file program?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC