你可以把这个DataTable里“name”这一列设为主键,然后用同样的办法find就是了

解决方案 »

  1.   

    还是给你个例子吧DataColumn[] pk = {
                         ds.Tables[0].Columns["name"]
                       }
    ds.Tables[0].PrimaryKey = pk;
      

  2.   

    也可以用DataView的RowFilter:
    DataView DV = dataset.Tables[0].DefaultView;
    DV.RowFilter = " name=wang";
    然后你想取值的话:
    先判断是否有此记录:
    if(DV.Count>0)
    {
    string id = DV[0]["id"].ToString();
    }
      

  3.   

    private void GetRowsByFilter(){
       DataTable myTable;
       myTable = DataSet1.Tables["Orders"];
       // Presuming the DataTable has a column named Date.
       string strExpr;
       strExpr = "Date > '1/1/00'";
       DataRow[] foundRows;
       // Use the Select method to find all rows matching the filter.
       foundRows = myTable.Select(strExpr);
       // Print column 0 of each returned row.
       for(int i = 0; i < foundRows.Length; i ++){
          Console.WriteLine(foundRows[i][0]);
       }
    }