各位大侠,请问asp.net上传excel,怎么判断excel内容是否重复,

解决方案 »

  1.   

    读取EXCEL
    判断DataTable里是否有重复
      

  2.   

    将excel中数据放到数据源中.然后对数据源进行判断!
      

  3.   


    string excelConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=\"Excel 8.0;HDR=No;IMEX=1\"";
                OleDbConnection clconnection = new OleDbConnection(excelConnectionStr);
                clconnection.Open();
                DataTable dt = clconnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
                DropDownList2.DataSource = dt;
                DropDownList2.DataTextField = dt.Columns[2].ToString().Trim();
                DropDownList2.DataBind();
                clconnection.Close();
                string excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
                string selecttext = "select * from [" + DropDownList2.SelectedItem.Text.ToString().Trim() + "]";
                OleDbDataAdapter da = new OleDbDataAdapter(selecttext, excelConnectionString);
                DataSet ds = new DataSet();
                da.Fill(ds);
      

  4.   


                    string excelConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
                    OleDbConnection olconnection = new OleDbConnection(excelConnectionStr);
                    olconnection.Open();
                    OleDbCommand cmd = new OleDbCommand("select * from [" + DropDownList2.SelectedItem.Text.ToString().Trim() + "]", olconnection);
                    OleDbDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        SqlConnection conn = BuildConnection.Buildsqlconnection();
                        SqlBulkCopy bulkcopy = new SqlBulkCopy(conn);
                        for (int i = 0; i < CheckBoxList1.Items.Count; i++)
                        {
                            if (CheckBoxList1.Items[i].Selected == true)
                            {
                                bulkcopy.ColumnMappings.Add(CheckBoxList1.Items[i].Text.ToString().Trim(), CheckBoxList1.Items[i].Text.ToString().Trim());
                                choo = choo + CheckBoxList1.Items[i].Text.ToString().Trim() + ",";
                            }
                        }
                        if (choo.Length > 0)
                        {
                            choo = choo.Substring(0, choo.Length - 1);
                        }
                        cmd.Connection.Close();
                        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                        DataTable dt = new DataTable();
                        da.Fill(dt);