Author |
Topic |
Taurib
Starting Member
5 Posts |
Posted - 2011-06-07 : 14:39:37
|
Greetings, does anyone know, that how can i order my database by "Name" column instead of ID column. I need to do this after, i have done my database module and LINQ to SQL. Well, i need to order them on my website in GridView.Also i have already made an event:protected void Name(object sender, GridViewSortEventArgs e) { } |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-06-07 : 15:14:54
|
You're gonna have to give us a bit more information on what you're doing, what you want...--Gail ShawSQL Server MVP |
|
|
Taurib
Starting Member
5 Posts |
Posted - 2011-06-07 : 15:23:27
|
I updated mine first post, well, i have done that i enabled sorting and in events below sorting i wrote there "Name", then it made me thisprotected void Name(object sender, GridViewSortEventArgs e) { }Problem is that, that i don't know, what do i have to write inside { } |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-06-07 : 17:46:44
|
From that, I don't know either. We can't see your machine, we can't read your mind, we don't know the background to the problem. Please be specific and detailed as to what you are trying to do--Gail ShawSQL Server MVP |
|
|
Taurib
Starting Member
5 Posts |
Posted - 2011-06-08 : 10:46:04
|
Well, ok i try to explain as good as i can1: I have made database module in MS Web developer.2: I generated database module from it and made it to MS SQL server manager as a Database3: I use that database in my web page4: (Problem starts here) Every time i make a new item to database, it orders it by ID, but in web page i would like that they would be ordered by nameFor conclusion, i have problem with ordering items in Database and/or Gridview. Because it shows the order by items ID not by it's name.example:Product 1Product 3Product 2Ordering is done by this that, when the items are added and so what is their ID number.I hope you understand my point |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-06-08 : 11:07:00
|
SELECT <some columns> FROM <your table>ORDER BY name |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-06-08 : 11:23:41
|
How are you doing data access? SQL statement? Entity framework? Linq? Something else?--Gail ShawSQL Server MVP |
|
|
Taurib
Starting Member
5 Posts |
Posted - 2011-06-08 : 11:42:09
|
quote: Originally posted by russell SELECT <some columns> FROM <your table>ORDER BY name
This didn't work, i forgot to say that my language is C# (if it matters)quote: Originally posted by GilaMonsterHow are you doing data access? SQL statement? Entity framework? Linq? Something else?
First i make entity, then i generate from module. Then i go to MS server manager R2 and paste the code and execute it. Then i use LINQ to SQL and there is my database connected. On web page i use GridView to see the database data. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-06-08 : 11:49:21
|
I don't believe that it didn't work if you pasted a SQL statement.Order By is the ONLY way to sort data server-side.In your case, use the LINQ orderby method. Or you can sort in your C# code |
|
|
Taurib
Starting Member
5 Posts |
Posted - 2011-06-08 : 12:47:41
|
quote: Originally posted by russell I don't believe that it didn't work if you pasted a SQL statement.Order By is the ONLY way to sort data server-side.In your case, use the LINQ orderby method. Or you can sort in your C# code
LINQ orderby method? Well i don't know what does it exactly means, but i have tried to write SELECT <some columns> FROM <your table>ORDER BY namecode to database, it allowed me to only leave "ORDER BY name" there, but nothing changed. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-06-08 : 13:24:33
|
If you're just sucking the whole table in, then somewhere (LINQ) it is converting your code to "SELECT * " with no ORDER BY clause.In this case, you can't guarentee the sort order.I don't know what you pasted that code snippet into, but if you paste it into your query editor, it will return as expected.You can google out the LINQ methods you need -- I'm no LINQ expert. But it is almost always more efficient to write a stored procedure and use that instead. |
|
|
|