Click here to Skip to main content
15,943,008 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Working on a window to manage admin logins.
I want a maximum of 5 signup in a way that the 6th one deletes the 1st DataRow from the DataBase.

query = "delete * from adminTable";

Is clearring all the rows from DataBase.

query = "delete * from adminTable where [USER NAMES] = 'singal' ";

Is clearring the row I've specified.
But I want the 1st row only, no matter what, to just get deleted.
Help please, thanks.
Updated 5-Jan-15 22:43pm
ArunRajendra 6-Jan-15 4:24am    
What fields do you have in your table? Give the design
Herman<T>.Instance 6-Jan-15 5:59am    
What database? What tablestructrure?
Salisu Shaibu 6-Jan-15 6:53am    
Hello Seniors.
I know you've come out to help me.
And I quite appreciate that.
But expect you to identify the DataTable and a field from the study of "query".
Unless their is something else you want to let me know.
Just make it plain please, I'm here to learn.
Nice attempt.

1 solution

Try the following:


MSAccess syntax is a little strange

An alternative if you have an AutoNumber ID field
DELETE FROM adminTable where ID = (SELECT MIN(ID) From adminTable)
but this is not good practice in multi-user environments
Share this answer
Salisu Shaibu 6-Jan-15 7:24am    
I applied the alternative query and got:
OleDbException was unhandled
Syntax error in FROM clause.
CHill60 6-Jan-15 8:23am    
You will need to change "ID" to the name of your Autonumber id column
Salisu Shaibu 6-Jan-15 9:23am    
Actually, I have ID column which was still AutoNumber and the primary key before the: Syntax error in FROM clause.
CHill60 6-Jan-15 10:38am    
Puzzling ... I'm running that query in Access 2010 and it's working fine. It might be the Ole driver that is moaning rather than the Access syntax. You could try that query in Access directly to see if it works on your version - if not then the first option should... you could always add SORT BY ID to the bit in brackets.
If the 2nd option does work in Access but not via OleDb then try saving the query in Access and calling the query from C# instead of the in-line SQL (which is usually a good option anyway)
Salisu Shaibu 6-Jan-15 11:36am    
I actually responded at about 1.5 hrs ago, I dont know why my phone refused to post my comment.
I was bussy using name of DataBase instead of TableName.
I didn't know what came over me.
Thanks man!
You're good.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900