Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Hey hi . . i am trying to run this part of code but problem is that it is not updating my access database
C#
con1.Open();
               
System.Data.OleDb.OleDbCommand cmd1 = new System.Data.OleDb.OleDbCommand(command, con1);
                
cmd1.ExecuteNonQuery();


System.Data.OleDb.OleDbCommand cmd2 = new System.Data.OleDb.OleDbCommand("UPDATE * from " + table_name + " order by Name", con1);

cmd2.ExecuteNonQuery();

con1.Close();


We are reading .mdb file and trying to sort it . . but it is not sorting :(
Posted
Updated 17-Apr-12 7:24am
v2
Comments
Vivek Krishnamurthy 17-Apr-12 13:26pm    
Make sure when you post a question,
1. headline should reflect what the problem is.
2. Do mention urgent, it is considered rude. This reduces chances of your question being answered.
[no name] 17-Apr-12 14:17pm    
Your whole premise is ridiculous. There is absolutely no need at all to sort data in a database table. You sort the data when it's queried.

You should be using the following :
C#
System.Data.OleDb.OleDbCommand cmd2 = new System.Data.OleDb.OleDbCommand("SELECT * from " + table_name + " order by Name", con1);
 
Share this answer
 
Comments
Injectors 17-Apr-12 13:32pm    
Nope !! its the same code line we are using . .
Mehdi Gholam 17-Apr-12 13:39pm    
If you look closely you will see that it is not what is in your question!
Injectors 17-Apr-12 13:44pm    
Ohhh ya . . but i did changes .. problem is that it is not saving tht file !
Refer to the following link on using Update statement with access.
UPDATE Statement (Microsoft Access SQL)[^]

also, looking at your update statement there is no set clause or where clause, what is it updating ?
 
Share this answer
 
Comments
Injectors 17-Apr-12 13:33pm    
Yes thr is no Where clause . . we just want to sort it according to Name u say . . .
Don't know what command you're passing in cmd1 (it also doesn't matter in this case) but using the ORDER BY Statement is only allowed in association with SELECT command.

Using
SQL
"SELECT * from " + table_name + " ORDER BY Name", con1
should work for you.

Please take care of capitalization when using SQL Commands, it's clearly readable then.

Regards
 
Share this answer
 
Comments
Injectors 17-Apr-12 13:40pm    
Yeahhh . . everything is working fine while debugging .. but main problem is that it is not saving that file !! It is sorting but not saving i guess
El_Codero 17-Apr-12 13:45pm    
As Mehdi Gholam also noticed you're using wrong association between commands (postet at same time), you'll need a subquery like this:
UPDATE table SET Name='something' WHERE Name in (SELECT * FROM Table WHERE Name='test' ORDER BY Name DESC);
Injectors 17-Apr-12 13:50pm    
ya i did that changes .. code is running successfully but it is not saving !
El_Codero 17-Apr-12 13:54pm    
you're using above UPDATE example now?if it's not saving I think you have some error in query command. please try to write the command as easy as it could be to make suke UPDATE command works, then add other statements like ORDER BY. we don't have a view into your database structure.
Injectors 17-Apr-12 14:13pm    
no m using select command . .
Sorting a database table is completely useless.

You sort data when you query it ; there is absolutely no reason to sort the table itself.
Let the data engine handle the database, and focus on your requirements.
 
Share this answer
 
Please pick one of the link from Maintaining sort order of database table rows[^]

Hope it helps :)
 
Share this answer
 

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