C# 如何在将数据导入sql server时解决此异常?

C# 如何在将数据导入sql server时解决此异常?,c#,asp.net,excel,C#,Asp.net,Excel,Microsoft Office Access数据库引擎找不到对象“Sheet1$$A7:B”。确保对象存在,并且正确拼写其名称和路径名 using (OleDbConnection excel_con = new OleDbConnection(conString)) { excel_con.Open(); string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.

Microsoft Office Access数据库引擎找不到对象“Sheet1$$A7:B”。确保对象存在,并且正确拼写其名称和路径名

using (OleDbConnection excel_con = new OleDbConnection(conString))
        {
            excel_con.Open();
            string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString();
            DataTable dtExcelData = new DataTable();

            //[OPTIONAL]: It is recommended as otherwise the data will be considered as String by default.
            dtExcelData.Columns.AddRange(new DataColumn[3] { new DataColumn("PersonId", typeof(int)),
            new DataColumn("Name", typeof(int)),
            new DataColumn("Salary",typeof(decimal)) });

            using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "$" + "A7:B]", excel_con))
            {
                oda.Fill(dtExcelData);
            }
            excel_con.Close();

您自己检查问题的可能重复项,然后您将看到您的对象必须是Sheet1$A7:B。请尝试将查询字符串更改为
“从[“+Sheet1+”A7:B]”中选择*”
,效果良好。非常感谢。