Click here to Skip to main content
15,892,269 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I used this entity code to display datagrid in descending order I'm using wpf c# and MySQL :

C#
baseEntities dc = new baseEntities();

       //display data in table in descending order 
  Mydatagrid.ItemsSource = dc.myentity.OrderByDescending(p => p.myColumn).ToList();


What I have tried:

I want to convert my code to paramatrized code .
I wish your help .
Posted
Updated 23-May-17 4:08am
Comments
CHill60 23-May-17 9:01am    
What do you mean by "paramatrized code" - what are you trying to parameterise?
EM_Y 23-May-17 9:23am    
with this code I can display my datagrid to descending order by defining the column , I used this entity code , and it's work for me , but I want to convert it to a type of mySQL query !

I used this and it's work with me :



using (MySqlConnection con = new MySqlConnection(ConString))
        {
     con.Open();

 CmdString = "SELECT * FROM database.mytable order by  mycolumn DESC ";
                     MySqlCommand cmd = new MySqlCommand(CmdString, con);
                     MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
                     DataTable dt = new DataTable("mytable");
                     sda.Fill(dt);
                     myDataGrid.ItemsSource = dt.DefaultView;

             }


Thank you for help .
 
Share this answer
 
v2
we need to use Func ...

baseEntities dc = new baseEntities();

Func<string> myColumnName = "ColumnName";


     //display data in table in descending order
Mydatagrid.ItemsSource = dc.myentity.OrderByDescending(myColumnName ).ToList();
 
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