DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   deleting the records of the MS access table using VB.NET (http://www.daniweb.com/forums/thread160198.html)

kritiohri Dec 1st, 2008 3:06 am
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.

reena12 Dec 1st, 2008 4:53 am
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()

kritiohri Dec 6th, 2008 3:12 am
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
cmd.ExecuteNonQuery()

reena12 Dec 6th, 2008 4:15 am
Re: deleting the records of the MS access table using VB.NET
 
Hi,
pls post your code

reena12 Dec 6th, 2008 4:16 am
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()

kritiohri Dec 8th, 2008 1:53 am
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]

reena12 Dec 8th, 2008 2:51 am
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

kritiohri Dec 8th, 2008 3:55 am
Re: deleting the records of the MS access table using VB.NET
 
Thanks a ton...I solved the problem


All times are GMT -4. The time now is 9:00 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC