1

5枚のExcelをアップロードしています。アップロード中に「TOO MANY FIELDS DEFINED」というエラーが表示されます

public DataSet ExportQCCheckData(string filepath)
{
    string path = filepath;
    OleDbConnection con;
    System.Data.DataTable dt = null;
    //Connection string for oledb
    string conn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + path + "; Extended Properties='Excel 8.0;IMEX=1;'";
    con = new OleDbConnection(conn);
    try
    {
        con.Open();
        //get the sheet name in to a table

        dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        String[] excelsheets = new String[dt.Rows.Count];
        int i = 0;
        //using foreach get the sheet name in a string array called excelsheets[]
        foreach (DataRow dr in dt.Rows)
        {
            excelsheets[i] = dr["TABLE_NAME"].ToString();
            i++;
        }
        DataSet ds = new DataSet();
        int cnt = 0;
        foreach (string temp in excelsheets)
        {
            if (temp == "BASIC$" || temp == "SHORT$" || temp == "CLASS$" || temp == "MEMO$" || temp == "SOURCE$")
            {
                string query = "select * from [" + temp + "]";
                OleDbDataAdapter adp = new OleDbDataAdapter(query, con);
                adp.Fill(ds, temp);
                cnt++;
            }
        }
        if (cnt != 5)
        {
            ds = null;
        }
        return ds;
    }
    catch (Exception ex)
    {
        Console.Write(ex.Message);
        DataSet ds = null;
        return ds;
    }
    finally
    {
        con.Close();
    }
}
4

2 に答える 2

1

エラーは、Excel シートのフィールド数に属しています。Excel シートを追加してください。Excelシートに多くの列が含まれていないことを確認する必要があります

于 2012-07-02T06:43:59.853 に答える
0

この問題は、Excel に多数の列が含まれていることが原因です。つまり、空のセルをすべて選択するだけです

コントロール -

次に、Excelシートをアップロードします。アップロードしました。

于 2012-07-12T11:21:32.303 に答える