Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i using data set to show data what i want to how to sort may data form the data table i have 2 code to use in my data one of them is sqlcode and the another one is c# code
i want to sort the ( Answer column from A to Z ) .

SQL
SELECT        TOP (100) PERCENT Subscriber_No, Subscriber_Name, Contract_No, ID_No, Category, Phone_Number, Phone_NumberWork, Last_Deact_Date, Current_Status, Status_Reason, Activation, Contract_Nationality, allocated, 
                         collected, id, allocated - collected AS remaining, company_name, indebtedness_name, username, answer, noanswer
FROM            dbo.indebtedness
ORDER BY answer, noanswer


my c# code

C#
string mainconn = ConfigurationManager.ConnectionStrings["MY"].ConnectionString;
            using (SqlConnection sqlconn = new SqlConnection(mainconn))
            {
                sqlconn.Open();

                using (SqlCommand sqlcomm = new SqlCommand("SELECT * FROM remaining WHERE username=@username", sqlconn))
                {
                    sqlcomm.Parameters.AddWithValue("@username", txtusername.Text);
                    using (SqlDataAdapter sda = new SqlDataAdapter(sqlcomm))
                    {

                        ds = new DataSet();
                        sda.Fill(ds);
                        
                        ds.Tables[0].DefaultView.Sort = "answer";


                    }
                }
                
                dataGridView1.DataSource = ds.Tables["remaining"];
                Subscriber_No.Text = ds.Tables[0].Rows[i]["Subscriber_No"].ToString();
                Subscriber_Name.Text = ds.Tables[0].Rows[i]["Subscriber_Name"].ToString();
                Contract_No.Text = ds.Tables[0].Rows[i]["Contract_No"].ToString();
                ID_No.Text = ds.Tables[0].Rows[i]["ID_No"].ToString();
                Category.Text = ds.Tables[0].Rows[i]["Category"].ToString();
                Phone_Number.Text = ds.Tables[0].Rows[i]["Phone_Number"].ToString();
                Phone_NumberWork.Text = ds.Tables[0].Rows[i]["Phone_NumberWork"].ToString();
                Last_Deact_Date.Text = ds.Tables[0].Rows[i]["Last_Deact_Date"].ToString();
                Current_Status.Text = ds.Tables[0].Rows[i]["Current_Status"].ToString();
                Status_Reason.Text = ds.Tables[0].Rows[i]["Status_Reason"].ToString();
                Activation.Text = ds.Tables[0].Rows[i]["Activation"].ToString();
                Nationality.Text = ds.Tables[0].Rows[i]["Contract_Nationality"].ToString();
                Allocated.Text = ds.Tables[0].Rows[i]["allocated"].ToString();
                Collected.Text = ds.Tables[0].Rows[i]["collected"].ToString();
                Remaining.Text = ds.Tables[0].Rows[i]["remaining"].ToString();
                Company.Text = ds.Tables[0].Rows[i]["company_name"].ToString();
                Indebtedness.Text = ds.Tables[0].Rows[i]["indebtedness_name"].ToString();
}


What I have tried:

C#
using (SqlDataAdapter sda = new SqlDataAdapter(sqlcomm))
                    {

                        ds = new DataSet();
                        sda.Fill(ds);
                        DataTable dt = new DataTable();
                        dt.DefaultView.Sort = "answer desc";
                        dt = dt.DefaultView.ToTable();
                        


                    }
Posted
Updated 14-Feb-19 12:09pm
v3
Comments
Richard MacCutchan 14-Feb-19 7:39am    
What is the question?
el_tot93 14-Feb-19 7:43am    
i want to sort my column from A to Z in the from when im using dataset
Richard MacCutchan 14-Feb-19 8:00am    
You already have an ORDER BY clause in your stored procedure.
el_tot93 14-Feb-19 8:11am    
that is the problem i don't know why it didn't sort
Richard MacCutchan 14-Feb-19 8:02am    

1 solution

How do you know it "didn't sort".

"Answer, No Answer" most likely being "bools", all you get is 2 big chucks sorted as to 0's and 1's.

With the "top 100" ... mostly likely being all 0's.
 
Share this answer
 
Comments
el_tot93 17-Feb-19 0:31am    
that what i want when i open it my c# windows application it start with the 1 after that 0 what i want to start with the 0 or null after that 1 or not null

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