anubis7000
Programmer
Hi,
I am trying to create a delete button on my ASP.net webpage. I am using a ms access db as my backend.
Here is my code:
Protected Sub DELETE_BTN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DELETE_BTN.Click
'PET_GRID is the name of my datagrid
Dim foundrec As Boolean
foundrec = False
Dim pet_link As ADODB.Connection
pet_link = New ADODB.Connection
Dim pet_record As ADODB.Recordset
pet_record = New ADODB.Recordset
Dim pet_path As String
pet_path = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator.DAMAGEINC\My Documents\Visual Studio 2005\WebSites\WebSite1\App_Data\pets.mdb;"
pet_link.Open(pet_path)
pet_record.Open("SELECT * FROM PET", pet_link, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
'creates a link to the backend access database
pet_record.MoveFirst()
Do While Not pet_record.EOF
If pet_record.Fields("PET_ID").Value = PET_GRID.SelectedValue Then
'PET_GRID.SelectedValue returns the value of "PET_ID" of the currently selected record in the grid
pet_record.Delete(ADODB.AffectEnum.adAffectCurrent)
pet_record.Update()
MsgBox("Name Successfully deleted", vbInformation)
foundrec = True
End If
pet_record.MoveNext()
Loop
'goes to the first record in the backend database and tries to find the record that has the same PK as the one that
'is currently selected in the grid. Once found, it deletes that record
If foundrec = False Then
MsgBox("No matching record found", MsgBoxStyle.Exclamation)
End If
pet_record.Close()
PET_GRID.DataBind()
End Sub
This code works, however, if I do not have a message box at the end that says "Name Successfully deleted", the webpage will not update, and will still display the record, even though it no longer exists.
Any suggestions? Also, the method I am using to connect/open the backend database seems inefficient, as I have seen other code that uses temporary datasets, though I am not sure how to implement it myself.
Thanks in advance.
I am trying to create a delete button on my ASP.net webpage. I am using a ms access db as my backend.
Here is my code:
Protected Sub DELETE_BTN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DELETE_BTN.Click
'PET_GRID is the name of my datagrid
Dim foundrec As Boolean
foundrec = False
Dim pet_link As ADODB.Connection
pet_link = New ADODB.Connection
Dim pet_record As ADODB.Recordset
pet_record = New ADODB.Recordset
Dim pet_path As String
pet_path = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator.DAMAGEINC\My Documents\Visual Studio 2005\WebSites\WebSite1\App_Data\pets.mdb;"
pet_link.Open(pet_path)
pet_record.Open("SELECT * FROM PET", pet_link, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
'creates a link to the backend access database
pet_record.MoveFirst()
Do While Not pet_record.EOF
If pet_record.Fields("PET_ID").Value = PET_GRID.SelectedValue Then
'PET_GRID.SelectedValue returns the value of "PET_ID" of the currently selected record in the grid
pet_record.Delete(ADODB.AffectEnum.adAffectCurrent)
pet_record.Update()
MsgBox("Name Successfully deleted", vbInformation)
foundrec = True
End If
pet_record.MoveNext()
Loop
'goes to the first record in the backend database and tries to find the record that has the same PK as the one that
'is currently selected in the grid. Once found, it deletes that record
If foundrec = False Then
MsgBox("No matching record found", MsgBoxStyle.Exclamation)
End If
pet_record.Close()
PET_GRID.DataBind()
End Sub
This code works, however, if I do not have a message box at the end that says "Name Successfully deleted", the webpage will not update, and will still display the record, even though it no longer exists.
Any suggestions? Also, the method I am using to connect/open the backend database seems inefficient, as I have seen other code that uses temporary datasets, though I am not sure how to implement it myself.
Thanks in advance.