Question

how do i store the data i get from select statement into textbox.
i don't have any idea how to do this because this is my first time using foxpro i need this for my job application pls help me.
table name: emp4win
idnum
firstname
lastname
middlename
address
contact

cm=thisform.cmb1.Text
SELECT * FROM emp4win WHERE idnum=cm

data should be store in the following:

txtfirstname.text
txtlastname.text
txtmiddlename.text
txtaddress.text
txtaddress.text
txtcontact.text<br/>

No correct solution

OTHER TIPS

I'm going to answer supposing that the table is a native VFP .dbf file. There are many ways to do this, one would be to use normal VFP table processing, something like this:

USE emp4win IN 0                  &&Open table
LOCAL cm
cm = thisform.cmb1.Text
*Validate the value of the input textbox here
SELECT emp4win                    &&Make the table active
LOCATE FOR idnum=cm               &&Search for the row you want
IF NOT FOUND("emp4win")
    *Handle error when the record doesn't exists
ENDIF
*From now on, just populate textboxes with the found data
thisform.txtfirstname.text = emp4win.firstname
thisform.txtlastname.text = emp4win.middlename
thisform.txtmiddlename.text = emp4win.lastname
thisform.txtaddress.text = emp4win.address
thisform.txtcontact.text = emp4win.contact

Another option would be to use the built-in VFP SQL engine to do the search, pretty much as you've done, just with a catch, remember you must indicate where to save the result in order to use it, almost always using an INTO CURSOR clause (and then reading from that cursor), otherwise, like in your sample, it will be shown in a BROWSE window, which is totally useless in an application.

You were very close on your query and getting the result... If you use a SQL query without an "INTO" clause, it will just pull the results up in a browse display grid. By adding an INTO clause, it will put into some memory space, such as an array, or another cursor (but could also be another permanent table, but not suggested). Then, you can pull those values into the text properties of your textboxes...

I typically would do into a cursor (of which I prefix the result set with "C_" to know it is a temp cursor vs an actual table, and always pre-close the table in case I needed it left open for future use after the initial setting. This way, no remnant after the newest query.

use in select( "C_MyTmpResult" )
SELECT * FROM emp4win 
   WHERE idnum=cm
   into cursor C_MyTmpResult

data should be store in the following:

txtfirstname.Value = C_MyTmpResult.FirstName
txtlastname.Value = C_MyTmpResult.LastName
txtmiddlename.Value  = C_MyTmpResult.MiddleName
txtaddress.Value = C_MyTmpResult.Address
txtcontact.Value = C_MyTmpResult.Contact

You had 2 address lines, but no differentiation between an Address1 vs Address2 and might have just been a posting oversight, but context still holds true if you had two address lines.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top