Click here to Skip to main content
15,891,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi experts...

my database column is combination of alphabets and numbers. how can i sort numbers,after ending last alphabet. i using ms access2007 as db.

thanks in advance
Posted
Comments
Sunny_Kumar_ 19-Jun-12 2:03am    
share the data sample.
Sunny_Kumar_ 19-Jun-12 2:18am    
I mean to ask you for the data sample and what way you want it sorted. is it like:
ap16as4779
ka07dh8342
ta5hk1234
ap16as4778
ta5hk1233

and you want this to be sorted as:
ap16as4778
ap16as4779
ka07dh8342
ta5hk1233
ta5hk1234

please elaborate, so that I can get a better picture to make you understand.

Doing that in Access or SQL is pretty much impossible - it doesn't have a custom sort, just ascending or descending by character, according to the collation setting.

To do it in C# is pretty simple, but the exact mechanism is up to you as I don't know exactly how you are storing the data.

Personanally, I would implement a new IndianVehicleNumber class which implements IComparable, and do my own comparer.
 
Share this answer
 
Comments
OriginalGriff 19-Jun-12 3:02am    
That is so easy! :laugh:
No, seriously, it is...
All you have to do is handle the DataGridView SortCompare event, and set the e.SortResult

Assuming the VN is in column 0:
private Regex lastnumbers = new Regex(@"\d+\b", RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
private void myDataGridView_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
string sThis = myDataGridView.Rows[e.RowIndex1].Cells[0].Value as string;
string sThat = myDataGridView.Rows[e.RowIndex2].Cells[0].Value as string;
if (sThis != null && sThat != null)
{
Match mThis = lastnumbers.Match(sThis);
Match mThat = lastnumbers.Match(sthat);
e.SortResult = mThis.Value.CompareTo(mThat.Value);
return;
}
throw new NotImplementedException();
}

Even in Access you can, instead of using the drag and drop, input your own SQL Query.

The right query for this should already be posted in Code Project, pls refer to:

How to Sort Alphanumeric Data in SQL[^]
 
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