I am working with Monodevelop 4.0.1 that comes with the game engine Unity 5
64bit.

My ODBC driver in 64bit Windows 7 is:
Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb) 14.00.7010.1000
ACEODBC.DLL date: 15.feb.2013

public DataTable ReadExcel(string fileName, string sheetName)
{
  // ODBCJT32.DLL works with Unity 4.6 32bit, but not with Unity 5 64bit:
  //string connectionString = "Driver={Microsoft Excel Driver (*.xls)};
DriverId=790; Dbq=" + fileName + ";";
  // ACEODBC.DLL works with Unity 5 64bit:
  string connectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx,
*.xlsm, *.xlsb)}; DriverId=790; Dbq=" + fileName + ";";
  OdbcConnection connection = new OdbcConnection(connectionString);

  string commandText = "SELECT * FROM [" + sheetName + "$]";
  OdbcCommand command = new OdbcCommand(commandText, connection);

  connection.Open();
  OdbcDataReader dataReader = command.ExecuteReader();

  DataTable dataTable = new DataTable();
  dataTable.Load(dataReader); // works with ODBCJT32.DLL, but with
ACEODBC.DLL it throws NullReferenceException

  dataReader.Close();
  connection.Close();

  return dataTable;
}

The line: "dataTable.Load(dataReader);" throws this exception:

NullReferenceException: Object reference not set to an instance of an object
System.Data.Odbc.OdbcDataReader.GetColumnAttribute (Int32 column,
FieldIdentifier fieldId)
System.Data.Odbc.OdbcDataReader.GetSchemaTable ()

Any help would be appreciated!



--
View this message in context: 
http://mono.1490590.n4.nabble.com/32bit-OdbcDataReader-DataTable-Load-works-OK-but-64bit-throws-NullReferenceException-tp4665640.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to