如何从Excel中读取不为空的数据

   string strConn;

   string getsheet;

   getsheet = "select *from [Sheet1$] where [姓名]<>/"/"";

   strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + FilePath + ";Extended Properties=Excel 8.0;";

   OleDbConnection conn = new OleDbConnection(strConn);

   OleDbDataAdapter myCommand = new OleDbDataAdapter(getsheet,strConn);

   DataSet myDataSet = new DataSet();

   try

   {

    myCommand.Fill(myDataSet);

   }

   catch(Exception ex)

   {
    string test = ex.Message;

    Response.Write("<script>alert( '该Excel文件的工作表的名字不正确 !' )</script>");
    //ErrorPages(test);
   }

   return myDataSet; 

阅读更多
换一批

没有更多推荐了,返回首页