如题,已经建好了一个
               string strOdbcCon = @"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;
               Data Source=book1.xls;Extended Properties=Excel 8.0";
                OleDbConnection oledb = new OleDbConnection(strOdbcCon);
                OleDbDataAdapter oledat = new OleDbDataAdapter("select * from [Sheet1$]", oledb);
                DataTable dt = new DataTable();
                oledat.Fill(dt);
               this.dataGridView1.DataSource = dt.DefaultView;
这样是把一个表格的值传入 DataTable dt,中,但现在要在其中选出某个数,怎么办,求各位高手指点。急

解决方案 »

  1.   

    select * from [Sheet1$] where C9="12",这样怎么样,因为我没写过的! 
      

  2.   

    你可以把DataTable dt简单理解成一个数组,用dt.Row[i][j]来访问里面的内容。i(int)行号,j列号或字段名。
      

  3.   

    dt.select();
    http://msdn.microsoft.com/zh-cn/library/way3dy9w(VS.80).aspx
      

  4.   

    dt.Select(string FilterType);///FilterType过滤条件,
      

  5.   

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

  6.   

    比如数据库表中有个字段是Nameforeach(DataRow  dr in dt.Rows)
    {
       Console.Write(dr["Name"].toString());
    }
      

  7.   

    string 名称=dt.Row[第几行][列名称].Tostring();
    我经常这样用,希望能帮得上。