请问C#.net用什么方法连接excel文件,然后实行查询操作,将结果显示到form中。
哪位大侠等指点下,多谢。

解决方案 »

  1.   

    using System; 
    using System.Collections.Generic; 
    using System.Text; 
    using System.Data.Odbc; namespace ConnectExcel 

        class Program 
        { 
            static void Main(string[] args) 
            { 
                OdbcConnection con = new OdbcConnection(@\"Driver={Microsoft Excel Driver (*.xls)};DBQ=Excel/student.xls\"); 
            //    OdbcDataAdapter da=new OdbcDataAdapter();             OdbcCommand com = new OdbcCommand(\"select stuid,stuname from [student$]\", con); 
                con.Open(); 
                  OdbcDataReader dr = com.ExecuteReader(); 
                while (dr.Read()) 
                { 
                   Console.WriteLine(dr[0]); 
                   Console.WriteLine(dr[1]); 
                } 
                dr.Close(); 
                con.Close();         } 
        } 
      

  2.   

    对上面的补充,可以用odbc,oledb连excel,就像连ACCESS一样的,然后读到dataset或者datatable里,绑定到datagridview就行了