如何排序(我试试这个代码)? [英] How to sort ( I try this code )?

查看:67
本文介绍了如何排序(我试试这个代码)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用数据集显示数据我想要如何排序数据表中的数据我有2个代码在我的数据中使用其中一个是sqlcode而另一个是c#代码

i想要排序(答案栏从A到Z)。



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 ) .

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





我的c#代码





my c# code

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:

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();
                        


                    }

推荐答案

你怎么知道它没有排序。



答案,没有答案最有可能是bools,所有你得到的是2个大块头,排序为0和1。



前100名......很可能都是0。
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.


这篇关于如何排序(我试试这个代码)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆