Get data from Excel spreadsheet with wxDB/wxDBTable?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Get data from Excel spreadsheet with wxDB/wxDBTable?

Post by timg » Thu Jan 22, 2009 5:23 pm

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");
else
    m_textCtrl1->AppendText("\n\nIt returned FALSE\n\n");


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

}

Post Reply