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