f



Problem with MS Access Database

------=_NextPart_000_0038_01C56A17.539605A0
Content-Type: text/plain;
	charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Hello,
 
I'm using wxWidgets now a long time for designig my applications. This
weekend I tried first to use the Database classes, but I've got a
problem with them...
 
I've got an Microsoft Access Datenbase, with two tables:
Orte(ID, Staat, Name, and so on)
PLZOrte(ID, PLZ)
 
This tables are set into a relationship. The field ID ist the primary
key in Orte and set up the relation. Now I'd like to do a query to this
database in my program. 
 
Therefore I used a wxTable pointer:
m_PLZOrte = new wxDbTable( m_DB, "PLZOrt", 3);
m_PLZOrte->SetColDefs(0, "ID", DB_DATA_TYPE_INTEGER, &m_PLZOrtSatz.ID,
SQL_C_NUMERIC, sizeof(m_PLZOrtSatz.ID), true, true);
m_PLZOrte->SetColDefs(1, "Name", DB_DATA_TYPE_VARCHAR,
&m_PLZOrtSatz.Ort, SQL_C_WXCHAR, sizeof(m_PLZOrtSatz.Ort), true, true);
m_PLZOrte->SetColDefs(2, "PLZ", DB_DATA_TYPE_VARCHAR, &m_PLZOrtSatz.PLZ,
SQL_C_WXCHAR, sizeof(m_PLZOrtSatz.PLZ), true, true);
 
I want to get back the fields ID, Name and PLZ from the query, like I
set with the SetColDefs() funktion.
 
Then I set the From and Where Clause to get a Join:
m_PLZOrte->SetWhereClause(wxT("Orte.ID = PLZOrt.ID"));
m_PLZOrte->SetFromClause(wxT("Orte"));
 
PLZOrt is the Basetable and PLZOrt the second table.
 
But when I execute this query with m_PLZOrte->Query() it doesn't work.
The function returns false every time. 
 
The connection to the database can be set up correct, I think, because
this fuction return no error...
 
Can anyone tell me, what I'm doing wrong?
 
Thanks in advance
Daniel

------=_NextPart_000_0038_01C56A17.539605A0
Content-Type: text/html;
	charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<TITLE>Nachricht</TITLE>

<META content=3D"MSHTML 6.00.2900.2627" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial=20
size=3D2>Hello,</FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial size=3D2>I'm =
using wxWidgets=20
now a long time for designig my applications. This weekend I tried first =
to use=20
the Database classes, but I've got a problem with =
them...</FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial size=3D2>I've =
got an=20
Microsoft Access Datenbase, with two tables:</FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial =
size=3D2>Orte(ID, Staat,=20
Name, and so on)</FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial =
size=3D2>PLZOrte(ID,=20
PLZ)</FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial size=3D2>This =
tables are set=20
into a relationship. The field ID ist the primary key in Orte and set up =
the=20
relation. Now I'd like to do a query to this database in my program.=20
</FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial =
size=3D2>Therefore I used a=20
wxTable pointer:<BR></FONT></SPAN><SPAN class=3D578442219-05062005><FONT =

size=3D2><FONT face=3DArial>m_PLZOrte =3D </FONT></FONT><FONT =
face=3DArial=20
size=3D2>new</FONT><FONT size=3D2><FONT face=3DArial> wxDbTable( m_DB, =
"PLZOrt",=20
3);</FONT></FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005></SPAN><SPAN =
class=3D578442219-05062005><FONT=20
size=3D2><FONT face=3DArial>m_PLZOrte-&gt;SetColDefs(0, "ID", =
DB_DATA_TYPE_INTEGER,=20
&amp;m_PLZOrtSatz.ID, SQL_C_NUMERIC, </FONT></FONT><FONT =
face=3DArial><FONT=20
size=3D2>sizeof</FONT><FONT size=3D2>(m_PLZOrtSatz.ID), </FONT><FONT=20
size=3D2>true</FONT><FONT size=3D2>, </FONT><FONT =
size=3D2>true</FONT></FONT><FONT=20
size=3D2><FONT face=3DArial>);</FONT></FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT size=3D2><FONT=20
face=3DArial>m_PLZOrte-&gt;SetColDefs(1, "Name", DB_DATA_TYPE_VARCHAR,=20
&amp;m_PLZOrtSatz.Ort, SQL_C_WXCHAR, </FONT></FONT><FONT =
face=3DArial><FONT=20
size=3D2>sizeof</FONT><FONT size=3D2>(m_PLZOrtSatz.Ort), </FONT><FONT=20
size=3D2>true</FONT><FONT size=3D2>, </FONT><FONT =
size=3D2>true</FONT></FONT><FONT=20
size=3D2><FONT face=3DArial>);</FONT></FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT size=3D2><FONT=20
face=3DArial>m_PLZOrte-&gt;SetColDefs(2, "PLZ", DB_DATA_TYPE_VARCHAR,=20
&amp;m_PLZOrtSatz.PLZ, SQL_C_WXCHAR, </FONT></FONT><FONT =
face=3DArial><FONT=20
size=3D2>sizeof</FONT><FONT size=3D2>(m_PLZOrtSatz.PLZ), </FONT><FONT=20
size=3D2>true</FONT><FONT size=3D2>, </FONT><FONT =
size=3D2>true</FONT><FONT=20
size=3D2>);</FONT></FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial =
size=3D2></FONT></SPAN><SPAN=20
class=3D578442219-05062005><FONT face=3DArial><FONT=20
size=3D2></FONT></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial><FONT =
size=3D2>I want to get=20
back the fields ID, Name and PLZ from the query, like I set with the=20
SetColDefs() funktion.</FONT></FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial><FONT=20
size=3D2></FONT></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial><FONT =
size=3D2>Then I set the=20
>From and Where Clause to get a Join:</FONT></FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005></SPAN><SPAN=20
class=3D578442219-05062005><FONT><FONT size=3D2><FONT size=3D2><FONT=20
face=3DArial>m_PLZOrte-&gt;SetWhereClause(wxT("Orte.ID =3D=20
PLZOrt.ID"));</FONT></FONT></FONT></FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT><FONT size=3D2><FONT =
size=3D2><FONT=20
face=3DArial>m_PLZOrte-&gt;SetFromClause(wxT("Orte"));</FONT></FONT></FON=
T></FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT><FONT size=3D2><FONT =
size=3D2><FONT=20
face=3DArial></FONT></FONT></FONT></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT><FONT size=3D2><FONT =
size=3D2><FONT=20
face=3DArial>PLZOrt is the Basetable and PLZOrt the second=20
table.</FONT></FONT></FONT></FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT><FONT size=3D2><FONT =
size=3D2><FONT=20
face=3DArial></FONT></FONT></FONT></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT><FONT size=3D2><FONT =
size=3D2><FONT=20
face=3DArial>But when I execute this query with m_PLZOrte-&gt;Query() it =
doesn't=20
work. The function returns false every time.=20
</FONT></FONT></FONT></FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial size=3D2>The =
connection to=20
the database can be set up correct, I think, because this fuction return =
no=20
error...</FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial size=3D2>Can =
anyone tell me,=20
what I'm doing wrong?</FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial size=3D2>Thanks =
in=20
advance</FONT></SPAN></DIV>
<DIV><SPAN class=3D578442219-05062005><FONT face=3DArial=20
size=3D2>Daniel</FONT></SPAN><SPAN =
class=3D578442219-05062005><FONT><FONT=20
size=3D2><FONT size=3D2></DIV></FONT></FONT></FONT></SPAN></BODY></HTML>

------=_NextPart_000_0038_01C56A17.539605A0--

0
dannyp1202
6/5/2005 7:41:35 PM
comp.soft-sys.wxwindows 21076 articles. 0 followers. Post Follow

2 Replies
1123 Views

Similar Articles

[PageSpeed] 1

dannyp1202@arcor.de schrieb:

> I've got an Microsoft Access Datenbase, with two tables:
> Orte(ID, Staat, Name, and so on)
> PLZOrte(ID, PLZ)

[..]

> Can anyone tell me, what I'm doing wrong?

The problem is that you have a table object for every table. To access 
data from both tables, you have to merge the output. You need something 
like "SELECT Orte.ID, PLZOrte.PLZ, Orte.Name FROM Orte, PLZOrte WHERE 
PLZOrte.ID=Orte.ID".

pDb->SetFromClause(_T("Orte, PLZOrte"));
pDb->SetWhereClause(_T("Orte.ID=PLZOrte.ID"));
pDb->Query();

I don't know how (i.e. the table definition) the wxDbTable class has to 
be initialized because I build my SQL statements by hand (IMHO it's much 
easier).

Regards,
Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org

0
mjscod
6/5/2005 8:07:17 PM
Hello,

Thank you for your answer, Mark.
Can you tell me, how I can built the SQL statements by hand? I've found
only this way, with the SetFromClause() and so on.=20

But this way you told me, works ;) The manual said I mustn't put the
Basetable in the From Clause and so I didn't do that. But it seems that
it is necessary to do that.

But the result variables are empty. I will check my programm for this.
Perhaps I'll find out why ;)

Thank you

Bye
Daniel



-----Urspr=FCngliche Nachricht-----
Von: Mark Junker [mailto:mjscod@gmx.de]=20
Gesendet: Sonntag, 5. Juni 2005 22:07
An: wx-users@lists.wxwidgets.org
Betreff: Re: Problem with MS Access Database

The problem is that you have a table object for every table. To access=20
data from both tables, you have to merge the output. You need something=20
like "SELECT Orte.ID, PLZOrte.PLZ, Orte.Name FROM Orte, PLZOrte WHERE=20
PLZOrte.ID=3DOrte.ID".

pDb->SetFromClause(_T("Orte, PLZOrte"));
pDb->SetWhereClause(_T("Orte.ID=3DPLZOrte.ID"));
pDb->Query();

I don't know how (i.e. the table definition) the wxDbTable class has to=20
be initialized because I build my SQL statements by hand (IMHO it's much

easier).

Regards,
Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org



---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org

0
dannyp1202
6/5/2005 8:13:29 PM
Reply: