当前位置:Gxlcms > 数据库问题 > 错误:“未在本地计算机上注册“microsoft.ACE.oledb.12.0”

错误:“未在本地计算机上注册“microsoft.ACE.oledb.12.0”

时间:2021-07-01 10:21:17 帮助过:2人阅读

public static DataTable GetData(string fileName) 2 { 3 if (!File.Exists(fileName)) return null; 4 //string connStr = string.Format(@"Provider=MMicrosoft.ACE.OLEDB.12.0;data source=‘{0}‘;Extended Properties=‘Excel 8.0;HDR=YES;IMEX=1‘;", fileName); 5 string connStr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=‘{0}‘;Extended Properties=‘Excel 12.0;HDR=YES;IMEX=1‘;", fileName); 6 using (OleDbConnection conn = new OleDbConnection(connStr)) 7 { 8 9 try 10 { 11 conn.Open(); 12 DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); 13 var tableName = dt.Rows[0][2].ToString().Trim(); 14 string cmdTxt = string.Format("select * from [{0}]", tableName); 15 16 // Trace.Write("查询表:" + cmdTxt); 17 OleDbDataAdapter da = new OleDbDataAdapter(cmdTxt, conn); 18 DataSet ds = new DataSet(); 19 da.Fill(ds); 20 return ds.Tables[0]; 21 } 22 catch (Exception e) 23 { 24 25 // Trace.WriteLine("GetData错误: " + e.Message); 26 return null; 27 } 28 finally 29 { 30 conn.Close(); 31 } 32 } 33 }

 

错误:“未在本地计算机上注册“microsoft.ACE.oledb.12.0”

标签:

人气教程排行