deleted in data set not in database

cjaymcmeans

Well-known member
Joined
Jan 12, 2005
Messages
85
Programming Experience
3-5
im having trouble deleting records in my database.. i just started using vs.net...
i was successful in deleting rows in datasets.. my problem is that i want to delete the records also... i've used oledbcommands... command adapters but sadly i am yet to succeed in deleting the rows that i have deleted in the dataset in the database... hope you guys can help..
Dim DelPrm As OleDb.OleDbParameter

Dim DelCom As New OleDbCommand

DelCom.CommandText = ("delete from users where userid='" & Trim(IDstr) & "'")

DelCom.Connection = XConn

'DelCom.CreateParameter()

'DelPrm = DelCom.Parameters.Add("@UID", IDstr)

'DelPrm.SourceVersion = DataRowVersion.Original

MyAdpUser = Nothing

MyAdpUser = New OleDbDataAdapter

MyAdpUser.DeleteCommand = DelCom

Try

MyAdpUser.Update(MyDstUser, "Users")

Catch ex As Exception

MsgBox(ex.ToString)

End Try

this doesnt seem to work... i dont know why...
im kinda stuck here... so im very much open to any suggestion you guy might come up with... tnx...
 
I have a couple of ?'s. Is the database a MS Access DB? If yes, do you have a DataAdpater configured to that database (ie with sql statements? And did you use that same DataAdapter to generate a dataset for that db? How do you view the db?
I just got done with an app for my friends company. He needed something to calculate and track the gas mileage of his company vehicles. So I can add, delete vehicles in one db and the same in the db with all of the vehicles records.
 
I haven't tested this so I may be wrong, but I believe that if you want to execute the delete command you specified against a databse you should use OleDbCommand.ExecuteNonQuery(). I think that OleDbDataAdapter.Update() is for use with a parameterised command when you have already deleted the rows from their respective DataTables.
 
Last edited:
I have very well experienced this thing with Access. It is better to use the executenonquery() method instead of adapter.update
 
Back
Top