Somebody2


I select data from an SQL database and want to display that information in a list box, but am having trouble getting the data to display.

Select Statement -

Code Snippet

SELECT first, last FROM parents WHERE parents.last = m.lname INTO ARRAY pinfo

Now I want to display first and last in a list box, but don't know how. Is it best to save it into an array, or should I save the data as a cursor or table

I know if I want to display the first item in the array, I could go

Code Snippet

thisform.List1.AddItem(pinfo(1,1))

This will only display the first name of the first item in the array. It won't display "first last" and it won't display the second, third, etc. names in the array.



Re: SQL Select to ListBox

Naomi Nosonovsky


There are multiple ways to go. You can use an array, but then this array should be an object property. You can either have it as a listbox property (you can add it in its Init method with AddProperty method or have a special listbox class) or you can have it as a form's property.

Let's assume it's a form property called arrParents[1]

Then select ... into array thisform.arrParents

and

thisform.List.RowSourceType = 5

thisform.List1.RowSource = [thisform.arrParents] && string variable with the name of array

You can, of course, use a cursor as a RowSource or just a select statement.

So, the choice is yours.






Re: SQL Select to ListBox

Somebody2

Well, Itried adding the following instead of the additem stuff.

Code Snippet

thisform.List1.RowSourceType = 5

thisform.List1.RowSource = 'pinfo'

It adds the array items to listbox, but the actual names (values) don't appear. The listbox is still white, and it lets you select white names.





Re: SQL Select to ListBox

Naomi Nosonovsky

I'm not sure what you're talking about and unfrotunately you didn't read my message. I said, that we can not use array the way you did. We need this array to be a form property or a listbox property.

Add a new property to your form (could be pInfo[1]) if you insist on the pInfo as the array name. Then in all the rest of the code you need to reference it as thisform.pInfo and not just pInfo.





Re: SQL Select to ListBox

Vladimir Zografski

Code Snippet

ADDPROPERTY(ThisForm,'pinfo(1)')
SELECT first, last FROM parents WHERE parents.last = m.lname INTO ARRAY ThisForm.pinfo
thisform.List1.RowSourceType = 5
thisform.List1.RowSource = 'Thisform.pinfo'






Re: SQL Select to ListBox

CetinBasoz

Code Snippet

* listbox.init - or form.init or anywhere you want it to initialize

with this

.Addproperty( 'lName', '' )

.RowSourceType = 3

.RowSource = "select first - (' '+ last) as fullname"+;

" from parents where parents.last == this.lName into cursor crsNames"

endwith

Code Snippet

* when lName is available or changes

with thisform.myList

.lName = "whatever"

.ListIndex = 0

.Requery()

endwith

This is my preferance (but you can do the same thing with array if you want).





Re: SQL Select to ListBox

Naomi Nosonovsky

IF you would like to use LIKE operator instead of =, I think, we may change select a bit

RowSource = [select Last, First from myTable where Last Like this.cLastName into cursor curInfo]

Make sure that this.cLastName ends on %, e.g. it would be 'A%', 'B%', etc.