Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

You may want to try this.

 

Dim comDelete As String = "DELETE * FROM Account_Table WHERE User_Name ='" & Global.LoggedUser & "';"

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted
SQL can be very nasty, be glad yours fits on a single line, and not several pages...:)

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...