DataTable.DefaultView.Sort="StartNo,EndNo asc";

解决方案 »

  1.   

    我是要按 EndNo-StartNo的差值排序 
    不是对两个列分别排序
      

  2.   

    写sql时就多加这一计算列即可
      

  3.   

    or you can use like this:DataTable.DefaultView.Sort="StartNo desc ,EndNo asc";either is ok!`
      

  4.   

    cpp2017(幕白兄):
    不能多加一列啊 因为我要根据这个表所做的修改  更新数据库的 tavor(龙双公子):
    StartNo desc ,EndNo asc这样不行的 
    就连查询分析器  也行不通
      

  5.   

    use Sql
    1.select * from youtable order by StartNo desc,EndNo asc2.Use DataTable To Create DataViewDataSet ds=new DataSet();
    SqlDataAdapter Da=new SqlDataAdapter("select * from youtable",ConnString);
    Da.Fill(ds,"V_Table1");
    /////
    ds.Tables["V_Table1"].DefaultView.Sort="StartNo desc ,EndNo asc";
      

  6.   

    i'm wrong ,i don't your target is that.
    now you can do as caap2017 said.first,you use sql string like thisSqlDataAdapter sda=new SqlDataAdapter("select *,(max_lvl-min_lvl) as sort from jobs order by sort",myconnection);
    sda.Fill(ds,"jobs");
    this.DataGrid1.DataSource=ds.Tables[0].DefaultView;
    this.DataGrid1.DataBind();you can dynamicly set the sortexpression like this:
    ds.Tables[0].DefaultView.Sort="sort asc";then i think you should use boundcolumn ,then you don't bind the sort column.i think then you will get what you want to get.
      

  7.   

    select EndNo-StartNo as sort from table order by sort
      

  8.   

    如果多增加一列的话那么就无法用  SqlDataAdapter.update() 的方法更新数据库了
      

  9.   

    this is some sentences in MSN Library:
    Windows Forms versus Web Forms DataGrid Control
       ............
    As with other Web server controls, it does not support two-way data binding. If you want to update data, you must write code to do this yourself. 
      .............i don't know it can be update database with the sqldataadpter.update() or not.so you must write the update code youself.