Page 1 of 1

Get data from Excel spreadsheet with wxDB/wxDBTable?

Posted: Thu Jan 22, 2009 5:23 pm
by timg
Does anyone have an example of getting data from an Excel spreadsheet using wxDB and wxDBTable?

I've been able to get the sheetnames and the field names from the sheet, but I can't get any data. SQL log shows an error:

Code: Select all

duplicates      1d0-87c	ENTER SQLSetConnectOption 
		HDBC                003C1830
		SQLINTEGER                 102 <SQL_AUTOCOMMIT>
		SQLPOINTER          0x00000000

duplicates      1d0-87c	EXIT  SQLSetConnectOption  with return code -1 (SQL_ERROR)
		HDBC                003C1830
		SQLINTEGER                 102 <SQL_AUTOCOMMIT>
		SQLPOINTER          0x00000000

		DIAG [S1C00] [Microsoft][ODBC Excel Driver]Optional feature not implemented  (106) 
This is the code:

Code: Select all

wxChar field[1025];
sheetname = db->SQLTableName(sheetname.c_str());
wxDbTable *table = new wxDbTable ( db, sheetname, col_names.GetCount(), wxT( "" ), wxDB_QUERY_ONLY );

table->SetColDefs(0, col_names.Item(2), DB_DATA_TYPE_VARCHAR, field, SQL_C_WXCHAR, sizeof(field), true, true);
wxString sql_qry;

sql_qry = "SELECT * FROM ["+sheetname+"]";
m_textCtrl1->AppendText(sql_qry );
if(table->QueryBySqlStmt( sql_qry ))
    m_textCtrl1->AppendText("\n\nIt returned TRUE\n\n");
    m_textCtrl1->AppendText("\n\nIt returned FALSE\n\n");

if (table->GetNext())
    m_textCtrl1->AppendText(wxString(field, wxConvUTF8)+"\n");