一道题是这样的:
有一个Dataset,里有一个Datatable,找出name="Lee"这列,数据所在的行号.要求高效.并且已知数据库连接字符串为"user id=sa;password=;initial catalog=northwind;datasource=localhost;connect Timeout=20";
大家帮帮忙.稍微完整点,也就是建立SqlConnection开始..麻烦了

解决方案 »

  1.   

    select identity(int,1,1) as ID, * from Tb where 1=1
    dv.RowFilter = "Name ='Lee'";
      

  2.   

    datatable是直接支持查找的
    DataTable.Select("name='Lee'");
    返回的是一个DataRow[]
      

  3.   

    综合3楼和4楼的
    一种用
    DataView视图的RowFilter属性解决
    DataView dv = dt.DefaultView;
    dv.RowFilter = "name = 'Lee'";一种可以用
    DataTable自己带的Select方法
      

  4.   

    当然也可以for(int i=0; i<dt.rows.count;i++)
    {
       if(dt.rows[i]["name"].ToString()=="Lee")
       {
           return i+1;
       }
    }
      

  5.   

    //获取行号,也就是id的值
    public string Getid(string Lee)
    {
    string id="";
    //table为表名;id为行号
    string sql="select id from table where name='"+Lee+"'";
    //创建命令对象
    SqlCommand cmd=new SqlCommand(sql,Conn);
    SqlDataAdapter da=new SqlDataAdapter(cmd);
    DataSet ds=new DataSet();
    da.Fill(ds);
    for(int i=0;i<ds.table[0].rows.count;i++)
    {
    id=ds.table[0].row[i]["id"].toString();
    }
    //返回行号
    return id;
    }
      

  6.   

    本身datatable就有一个select函数。我看,你是应该多看看msdn。当然,数据结构还是要的