Rankun Posted October 13, 2005 Posted October 13, 2005 Hope this is an easy one to fix. :) Basically I want to delete all records from the Account_Table that match the User_Name. There are dozens of records that match. I can delete one record using basically the same code if I match by ID. Any help is greatly appreciated. Thanks, Rankun I.E. ID (P-Key) User_Name Date * Action * 001 Jon Doe 09/17/2005 Should be deleted 023 Jon Doe 09/18/2005 Should be deleted 034 Jane Doe 09/17/2005 Should not be deleted 067 Jon Doe 09/23/2005 Should be deleted Here is my code: Private Function DeleteAccount() Dim MyCommand As OleDbCommand Dim MyConnection As OleDbConnection Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & Global.DataBaseLoc MyConnection = New OleDbConnection(connectString) 'cant delete multiple entries from the table with this command Dim comDelete As String = "DELETE FROM Account_Table WHERE User_Name = " & Global.LoggedUser MyCommand = New OleDbCommand(comDelete, MyConnection) MyCommand.Connection.Open() MyCommand.ExecuteNonQuery() MyCommand.Connection.Close() End Function Quote
Nate Bross Posted October 13, 2005 Posted October 13, 2005 You may want to try this. Dim comDelete As String = "DELETE * FROM Account_Table WHERE User_Name ='" & Global.LoggedUser & "';" Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Rankun Posted October 13, 2005 Author Posted October 13, 2005 Thanks Nate, Worked like a charm!!! I actually tried it with a *, but left out the ' marks :( Thanks again, Rankun Quote
Nate Bross Posted October 15, 2005 Posted October 15, 2005 SQL can be very nasty, be glad yours fits on a single line, and not several pages...:) Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Administrators PlausiblyDamp Posted October 15, 2005 Administrators Posted October 15, 2005 Thats why parameterised queries can be an enourmous help. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.