我从数据库中查询出新闻,绑定到DataGrid
如下:
==========================
标题    类别   作者   来源
xxxx     1     xxx   xxx
==========================
问题1:我的类别列加入的是类别表里一个类别的ID,请问我怎么将这个ID的类别的名字绑定到上面类别那列?

解决方案 »

  1.   

    象标题那几列直接用属性生成器里填入数据库字段名称,在给DataGrid绑定数据源
    private void selectNews(){
    string sql="select * from news order by n_Id desc";
    DataTable dt=asp.net.func.selectNewsClass(sql);
    //指定数据源
    newsTable.DataSource=dt.DefaultView;
    newsTable.DataBind();
    }
      

  2.   

    改一下SQL 试一下例如: select id,标题 ,(select 类别名 from 类别表  a where a .id = b.id) as 类别名称
    ,
     作者,   来源 news  b order by n_Id desc 
      

  3.   

    select t1.name t2.title t2.from t2.edit from table t1,table t2 where t1.id=t2.typeid
      

  4.   

    这个嘛,自然得在查询的时候,进行连接查询数据库还没学好?赶快看书去 ....SELECT
    标题 t2.类别名 作者 来源
    FROM 新闻表 t1
    JOIN 新闻类别表 t2
    ON t1.类别ID = t2.类别ID