我在使用c#Unity脚本中的ODBC访问.xsl文件中的数据。连接有效,我可以从文件中检索数据,但是我的元数据遇到问题。当我调用GetSchema(string)函数时,它会陷入无限的递归调用,直到它导致堆栈溢出。无论我尝试获得什么特定模式,都会发生此问题。在Unity中从excel中检索元数据
这里是我使用的代码:我就遇到了这个问题,我自己
string connectionString = "Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq=" + file + ";UNICODESQL=1;Unicode=yes;";
OdbcConnection dbCon = null;
OdbcDataReader dbData = null;
try
{
dbCon = new OdbcConnection(connectionString);
Debug.Log(connectionString);
dbCon.Open();
DataTable sheets = dbCon.GetSchema(OdbcMetaDataCollectionNames.Tables);
foreach(DataRow sheet in sheets.Rows)
{
string sheetName = sheet["TABLE_NAME"].ToString().Trim('\'').TrimEnd('$');
OdbcCommand dbCommand = new OdbcCommand("SELECT * FROM [" + sheetName + "$]", dbCon);
DataTable data = new DataTable(sheetName);
dbData = dbCommand.ExecuteReader();
data.Load(dbData);
}
}
catch (Exception ex)
{
if (ex != null)
{
Debug.LogError(ex.Message);
Debug.LogError(ex.StackTrace);
}
else
Debug.LogError("Exception raise loading '" + file + "'");
}
finally
{
if (dbData != null)
dbData.Close();
if (dbCon != null)
dbCon.Close();
}
}
欢迎来到SO,Wili。 – Brian
我不熟悉使用XLS作为数据源,但可能需要关闭连接吗? –