Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Problems with wxDb & wxDbTable

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Problems with wxDb & wxDbTable
#3083
Posted by: 2003-12-14 23:33:28
Hi, I already asked a question a few days ago (thanks for your help again upCase), but I already have a question again.

I wrote a wxWindows-Program and want to use a Database-Table to save and load some settings.
The follow code I wrote so far:

wxDbConnectInf *dci = new wxDbConnectInf(NULL, "DSN", "User", "PW");
if (!dci || !dci->GetHenv())
{
   wxLogMessage("Error");
   return;
}
wxDb *dab = wxDbGetConnection(dci);
wxDbTable *tbl = new wxDbTable(dab, "Table_Name", 4, "", false, "");
wxChar Field1[51];
wxChar Field2[16];
tbl->SetColDefs(1, "Field1", DB_DATA_TYPE_VARCHAR, Field1, SQL_C_CHAR, sizeof(Field1));
tbl->SetColDefs(2, "Field2", DB_DATA_TYPE_VARCHAR, Field2, SQL_C_CHAR, siezof(Field2));
tbl->Open();
tbl->SetWhereClause("");
tbl->SetOrderByClause("");
tbl->SetFromClause("");
if (!tbl->Query())
{
   wxMessage("Error");
   return;
}
while (tbl->GetNext())
{
   //Doing stuff with Field1 and Field2
}
delete tbl;
if (dab)
{
   wxDbFreeConnection(dab);
   dab = NULL;
}
wxDbCloseConnections();
delete dci;

The Problem is that he shows an error when I send the Query. The function returns with false.

I would really appreciate any help.
Thanks in advance.

Message2. Re: Problems with wxDb & wxDbTable
#3089
Posted by: upCASE 2003-12-15 21:09:39
Hi!
I'd say the error may come from
tbl->SetFromClause("");
You should specify the table from which you want to collect data. I'll see if I can confirm this when I'm home.
Maybe check if
tbl->Open();
worked or if this causes an error.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Mon 2024-10-7  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0