Tricky problem, help please! 
Author Message
 Tricky problem, help please!

This is a multi-part message in MIME format.

------=_NextPart_000_0001_01BCC8F2.4C0702E0
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

 I'm trying to populate a treeview control with a SQL statement. It's a =
recordcollection-database with separate tables for Artists, Category and =
Albums. The tricky part is as follows:

I want the root of the tree to view the categorys,under those, the =
Artists name, and under these their records. The thing is that in order =
to place the Artists under the right category, I have to use the 'unique =
key'. Here's the problem - if one Artist has more than one record, the =
SQL statement returns them all, resulting in the error "Key is not =
unique in collection"... I know ofcourse what that means, but how do I =
solve it/get around it? Thanks for any suggestions!

For k =3D 1 To Kategori.RecordCount
    tmpKatValue =3D Kategori("Kategorinr")
    tmpKatName =3D Kategori("Kategori")
       =20
    strSQL =3D "SELECT Artist, Album, Kategori  FROM lista " _
            & "WHERE Kategori =3D " & tmpKatValue
   =20
    'MsgBox strSQL
    Set Rst =3D db.OpenRecordset(strSQL)
    Rst.MoveLast
    Rst.MoveFirst
    'MsgBox "Hits: " & Rst.RecordCount
   =20
    'populate tree:

      For o =3D 1 To Rst.RecordCount
      MsgBox Kategori("Kategori") & ", " & Rst("Artist")
      Set nodX =3D TreeView1.Nodes.Add(tmpKatName, tvwChild, =
Rst("Artist"), Rst("Artist"))
      tmpKey =3D Rst("Artist")
      Set nodX =3D TreeView1.Nodes.Add(tmpKey, tvwChild, Rst("Album"), =
Rst("Album"))
      Rst.MoveNext
    Next o
  Kategori.MoveNext
  Next k=20

--=20
Pontus Edvardsson,

------=_NextPart_000_0001_01BCC8F2.4C0702E0
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.71.1008.3"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<P><FONT color=3D#000000 face=3DArial size=3D2>&nbsp;I'm trying to =
populate a treeview=20
control with a SQL statement. It's a recordcollection-database with =
separate=20
tables for Artists, Category and Albums. The tricky part is as=20
follows:</FONT></P>
<P><FONT color=3D#000000 face=3DArial size=3D2>I want the root of the =
tree to view the=20
categorys,under those, the Artists name, and under these their records. =
The=20
thing is that in order to place the Artists under the right category, I =
have to=20
use the 'unique key'. Here's the problem - if one Artist has more than =
one=20
record, the SQL statement returns them all, resulting in the error =
&quot;Key is=20
not unique in collection&quot;... I know ofcourse what that means, but =
how do I=20
solve it/get around it? Thanks for any suggestions!</FONT>
<P><FONT color=3D#000000 face=3DArial size=3D2><FONT>For k =3D 1 To=20
Kategori.RecordCount<BR>&nbsp;&nbsp;&nbsp; tmpKatValue =3D=20
Kategori(&quot;Kategorinr&quot;)<BR>&nbsp;&nbsp;&nbsp; tmpKatName =3D=20
Kategori(&quot;Kategori&quot;)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
<BR>&nbsp;&nbsp;&nbsp; strSQL =3D &quot;SELECT Artist, Album, =
Kategori&nbsp; FROM=20
lista &quot;=20
_<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&amp;=20
&quot;WHERE Kategori =3D &quot; &amp; tmpKatValue<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; 'MsgBox strSQL<BR>&nbsp;&nbsp;&nbsp; Set Rst =3D=20
db.OpenRecordset(strSQL)<BR>&nbsp;&nbsp;&nbsp;=20
Rst.MoveLast<BR>&nbsp;&nbsp;&nbsp; Rst.MoveFirst<BR>&nbsp;&nbsp;&nbsp; =
'MsgBox=20
&quot;Hits: &quot; &amp; Rst.RecordCount<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; 'populate tree:</FONT></FONT>
<P><FONT color=3D#000000 face=3DArial size=3D2><FONT></FONT></FONT><FONT =
color=3D#000000=20
face=3DArial size=3D2><FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For o =3D 1 =
To=20
Rst.RecordCount<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox=20
Kategori(&quot;Kategori&quot;) &amp; &quot;, &quot; &amp;=20
Rst(&quot;Artist&quot;)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set nodX =3D=20
TreeView1.Nodes.Add(tmpKatName, tvwChild, Rst(&quot;Artist&quot;),=20
Rst(&quot;Artist&quot;))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmpKey =3D=20
Rst(&quot;Artist&quot;)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set nodX =3D=20
TreeView1.Nodes.Add(tmpKey, tvwChild, Rst(&quot;Album&quot;),=20
Rst(&quot;Album&quot;))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
Rst.MoveNext<BR>&nbsp;&nbsp;&nbsp; Next o<BR>&nbsp; =
Kategori.MoveNext<BR>&nbsp;=20
Next k</FONT>&nbsp;</FONT>&nbsp;
<P><FONT color=3D#000000 face=3DArial size=3D2><BR>-- <BR>Pontus =
Edvardsson,<BR><A=20

</A></FONT></P></BODY></HTML>

------=_NextPart_000_0001_01BCC8F2.4C0702E0--



Sun, 12 Mar 2000 03:00:00 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. tricky query - please help

2. Tricky Update statement need help please...

3. A Tuff Tricky One - Please Help with Queries

4. challenge..very tricky sql statement..please help

5. Cloning problem -- please please please help

6. COMBO BOX, PLEASE HELP, PLEASE HELP, PLEASE HELP!

7. Tricky DB Problem..HELP!!

8. Help!: FileMaker Pro 4.0 question....tricky problem

9. Tricky ODPC problem. Please help, please.

10. newbie import/export basic problem, please help please

11. emergency please help me please please please


 
Powered by phpBB® Forum Software