在WEB 页面实现这样一个功能:
我的EXCEL第一列 存储了N多ID(P12345,P12346....),大概2000行左右。此文件在本地。
我有一个页面时是用来查询数据的,想根据这个excel ID 查询 数据。
本地文件和这个页面如何关联 去查询?

解决方案 »

  1.   

    先将Excel导入到DataSet
    然后遍历DataSet根据值去查
      

  2.   

       Try
                    Dim strReadExcel As String = "select * from  " & sheetTabelName
                    Dim excelConnStr As String = Nothing
                    excelConnStr = OleDbHelper.CreateExcelConnectionString(filePath, OleDbHelper.AccessMode.Export, OleDbHelper.FirstRowIsTitle.Yes)                ' Get data from excel or csv
                    Dim dr as DataReader= OleDbHelper.ExecuteReader(excelConnStr, CommandType.Text, strReadExcel)
       if (dr.Read())
                {
                               }
              
      

  3.   

    如果网页在本地,可以将excel文件和其放在一个目录,然后
    OleDbConnection xlsConn = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath("PList.xls") + "; Extended Properties = 'Excel 8.0; HDR=YES; IMEX=1'");
    xlsConn.Open();            string xlsSQL = "select * from [Sheet1] where [id]='xxx'";
                OleDbCommand xlsCmd = new OleDbCommand(xlsSQL, xlsConn);
                OleDbDataReader dr = xlsCmd.ExecuteReader();            while (dr.Read())
                {
                    string v1 = (dr[0].ToString().Trim() == "") ? "x" : dr[0].ToString  // 取第0列的值赋给v1
                }如果网页不在本地,那你要写一个上传的代码将excel上传到服务器再用以上方法操作即可。
      

  4.   

    楼上正解,直接把Excel文件当做数据源来访问
      

  5.   

    要比对,必须先做Excel文件导入代码,
    即便不保存到数据库,
    也需要遍历Excel比对筛选条件。
      

  6.   


    我已经实现了导入到Dataset,也能绑定到控件里。
    还有一个疑问,我dataset 里存储的都是ID。
    我想用 select * from table where productid in(dataset里的所有ID)
    请问怎么做?
      

  7.   

    select * from table where productid in(select f1 from [Sheet1])
      

  8.   

    select * from table where productid in(select id from tabname)
      

  9.   


    select * from table where productid in(dataset里的所有ID)我现在返回的是ds对象,请问我怎么做?
      

  10.   


    dataset里的所有ID 怎么变成 真正的所有ID 现在是对象啊。。
      

  11.   

                DataSet ds=new DataSet ();
                foreach(DataRow row in ds.Tables[0].Rows)
                {
                    string id= row["id"].ToString();
                    //你的操作
                }
      

  12.   


    bool isContains = false;
                foreach (DataRow r in ds.Tables["tableName"].Rows)
                {
                    if ((string)r["productid "] == "productid")
                    {
                        isContains = true;
                        break;
                    }
                }
      

  13.   

               DataSet ds=new DataSet ();
                        string strid;
                foreach(DataRow row in ds.Tables[0].Rows)
                {
                    strid+= row["id"].ToString()+',';
                    //你的操作
                }string sql="select * from table where productid in("+strid+")";
      

  14.   


     DataSet ds=new DataSet ();
                foreach(DataRow row in ds.Tables[0].Rows)
                {
                    string id= row["id"].ToString();
                    //你的操作
                }
    楼上的哥们,我excel 是1列的 ,2000多行数据 取DataRow row in ds.Tables[0].Rows 还是Columns?
    我用Columns怎么就能取1条?
      

  15.   


     以上基本解决 还有一个问题,如果我excel 的列 没有列名, 直接以PID123123开头怎么办?
      

  16.   

    你在导入到dataset的时候判断下是否为ID!!!!
    不为ID你导入到Dataset的时候你自己设置Dataset 里面的table 列名为ID!!!
      

  17.   

     foreach (DataRow row in dr.Rows) 
                    {
                        string str = row[0].ToString();
                    }
    这样吧 你就不用去知道他的列名了!!!