| | |
delete a record and update the dataset
Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
Hi everyone,
I hope you can help me.
I am using vb.net and trying to delete a row in an access database. Firstly, I find the row and confirm there's record. If there's a record I ask for deletion. I am using the values submitted via a text box.
Here is my code:
Private Sub btnDeleteUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteUser.Click
Dim reponse_del As Integer
If txtSearch.Text = "" Then
MessageBox.Show("Please type a user name into the text box")
End If
'clear and refill Dataset
OleDAPass.SelectCommand.Parameters("UserName").Value = txtSearch.Text
DS_Pass1.Clear()
OleDAPass.Fill(DS_Pass1)
'no records of the search name
If DS_Pass1.Tables("PwordStore").Rows.Count = 0 Then
MessageBox.Show("Record not found")
ElseIf DS_Pass1.Tables("PwordStore").Rows.Count = 1 Then 'record exists delete it
MessageBox.Show("Are you sure you wish to delete this user?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
If reponse_del = DialogResult.Yes Then
OleDAPass.SelectCommand.Parameters ("UserName").Value = txtSearch.Text
'delete row
DS_Pass1.Tables("PwordStore").Rows(0).Delete()
OleDAPass.Update(DS_Pass1, "PwordStore")
End If
DS_Pass1.PwordStore.AcceptChanges()
DS_Pass1.Clear()
txtSearch.Text = ""
End If
End Sub
The record is found ok but the database does not update. I can update newly added records.
Does anyone know what I'm doing wrong? Any guidance will be very much appreciated :-|
I hope you can help me.
I am using vb.net and trying to delete a row in an access database. Firstly, I find the row and confirm there's record. If there's a record I ask for deletion. I am using the values submitted via a text box.
Here is my code:
Private Sub btnDeleteUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteUser.Click
Dim reponse_del As Integer
If txtSearch.Text = "" Then
MessageBox.Show("Please type a user name into the text box")
End If
'clear and refill Dataset
OleDAPass.SelectCommand.Parameters("UserName").Value = txtSearch.Text
DS_Pass1.Clear()
OleDAPass.Fill(DS_Pass1)
'no records of the search name
If DS_Pass1.Tables("PwordStore").Rows.Count = 0 Then
MessageBox.Show("Record not found")
ElseIf DS_Pass1.Tables("PwordStore").Rows.Count = 1 Then 'record exists delete it
MessageBox.Show("Are you sure you wish to delete this user?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
If reponse_del = DialogResult.Yes Then
OleDAPass.SelectCommand.Parameters ("UserName").Value = txtSearch.Text
'delete row
DS_Pass1.Tables("PwordStore").Rows(0).Delete()
OleDAPass.Update(DS_Pass1, "PwordStore")
End If
DS_Pass1.PwordStore.AcceptChanges()
DS_Pass1.Clear()
txtSearch.Text = ""
End If
End Sub
The record is found ok but the database does not update. I can update newly added records.
Does anyone know what I'm doing wrong? Any guidance will be very much appreciated :-|
Hi
There must be something wrong with the command that you are using to update the database.
Why don't you try creating a commandbuilder, it will create the commands automaticallly for you.
something like this:
hope it helps
There must be something wrong with the command that you are using to update the database.
Why don't you try creating a commandbuilder, it will create the commands automaticallly for you.
something like this:
VB.NET Syntax (Toggle Plain Text)
If reponse_del = DialogResult.Yes Then OleDAPass.SelectCommand.Parameters ("UserName").Value = txtSearch.Text 'delete row DS_Pass1.Tables("PwordStore").Rows(0).Delete() Dim cmdbuilder As OleDbCommandBuilder = New oleDbCommandBuilder(OleDAPass) OleDAPass.update(DS_Pass1) End If
hope it helps
•
•
•
•
Originally Posted by williamrojas78
Hi
There must be something wrong with the command that you are using to update the database.
Why don't you try creating a commandbuilder, it will create the commands automaticallly for you.
something like this:
VB.NET Syntax (Toggle Plain Text)
If reponse_del = DialogResult.Yes Then OleDAPass.SelectCommand.Parameters ("UserName").Value = txtSearch.Text 'delete row DS_Pass1.Tables("PwordStore").Rows(0).Delete() Dim cmdbuilder As OleDbCommandBuilder = New oleDbCommandBuilder(OleDAPass) OleDAPass.update(DS_Pass1) End If
hope it helps
Thanks in advance
Hi
Try to enclose the database update in a try - catch statement and see exacly what the problem is.
Also try adding to the update statement the name of the table.
other than that, I can not think of anything else, everything seems to be fine.
Try to enclose the database update in a try - catch statement and see exacly what the problem is.
Also try adding to the update statement the name of the table.
VB.NET Syntax (Toggle Plain Text)
Try OleDAPass.update(DS_Pass1, "PwordStore") Catch x As Exception ' Error during Update, add code to locate error, reconcile ' and try to update again. End Try
other than that, I can not think of anything else, everything seems to be fine.
Hi again - I'm still stuck
i was wondering if my update statement could be wrong. It was generated by the access wizard :
It is also used to update the database when a new row is added and works fine for that. Does it need changing for the delete statement?
Please help me my deadline is getting very near.
Thanks
i was wondering if my update statement could be wrong. It was generated by the access wizard :
UPDATE PwordStore SET UserName = ?, Pword = ? WHERE (PwordNo = ?) AND (Pword = ? OR ? IS NULL AND Pword IS NULL) AND (UserName = ? OR ? IS NULL AND UserName IS NULL)Please help me my deadline is getting very near.
Thanks
Last edited by caramia; Jun 28th, 2006 at 8:12 pm.
Hi
The delete command and the update commad have to be different.
The delete command will be:
This is what my command builder gives me to delete records from my table. My table has the fields Rep, ID, SN, etc.
Another thing. When you use the command builder, did you declare the variables for the oleDBdataadapter, oleDBconnection and oleDbcommand outside the procedure?
regards
The delete command and the update commad have to be different.
The delete command will be:
VB.NET Syntax (Toggle Plain Text)
DELETE FROM Table_name WHERE ( ((? = 1 AND Rep IS NULL) OR (Rep = ?)) AND (ID = ?) AND ((? = 1 AND SN IS NULL) OR (SN = ?)) AND ((? = 1 AND Veh IS NULL) OR (Veh = ?)) AND ((? = 1 AND Hm IS NULL) OR (Hm = ?)) AND ((? = 1 AND Dt IS NULL) OR (Dt = ?)) )
This is what my command builder gives me to delete records from my table. My table has the fields Rep, ID, SN, etc.
Another thing. When you use the command builder, did you declare the variables for the oleDBdataadapter, oleDBconnection and oleDbcommand outside the procedure?
regards
![]() |
Similar Threads
- How to delete record from Datagrid and not from Database (ASP.NET)
- SQL Delete/Update Error (ColdFusion)
- datagrid delete function not auto update (ASP.NET)
- need to update each records after record deleted (PHP)
Other Threads in the VB.NET Forum
- Previous Thread: error : Could not access CDO.Message object
- Next Thread: Populate Listboxes with table data
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access account arithmetic array assignment basic box button buttons center check code component connectionstring convert crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist excel fade file-dialog firewall folder ftp generatetags hardcopy image images input insert intel isnumericfuntioncall math monitor navigate net networking opacity output passingparameters peertopeervideostreaming picturebox picturebox1 port problem problemwithinstallation project record reports" savedialog searchvb.net select serial shutdown string survey tcp temp temperature text textbox timer toolbox trim updown user useraccounts usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf





