How to add value in the ComboBox from the database at RunTime?

15 pts.
Tags:
ComboBox
Database programming
RunTime
I want to fetch the values from the database of a particular field in the combobox at run time...plz help me out

Answer Wiki

Thanks. We'll let you know when a new response is added.

This code is used in a Delphi form fmUserData, and is called on form.show, not create, to ensure data in combo box is up to date
The application uses MySQL server for data storage
cbucurr is a combo box in form fmUserData

// populate the strings list for the cbucurr combobox
fmUserData.cbucurr.items.clear; // make sure the combobox strings list is empty
fmUserData.qCurr.close; // qCurr is an ADO query linked to a table tCurr via an ADOConnection.
//My qCurr has a fixed SQL Select string that selects all currency codes, but you could insert a
// runtime select statement into the SQL.text property of qCuirr here
// My fixed SQL string is simply ‘Select currcode from tcurr’ ie I want all codes in tcurr
fmUserData.qCurr.open; // runs whatever select statement you have put in place
fmUserData.qCurr.first;
while (not fmUserData.qCurr.eof) do
begin
cbucurr.items.add(qcurr.FieldByName(‘currcode’).asstring);
// in above line, currcode is a field in the MySQL table tcurrr
fmUserData.qCurr.next;
end;

I have the combobox set to uppercase and to sort the list automatically.
Hope this helps.

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Denny Cherry
    What programming language are you using? It will be different in each language.
    66,360 pointsBadges:
    report
  • BrentSheets
    Kiti, to provide more information on your question -- simply click the "Discuss This Answer" button. Your comment will appear below. Thanks!
    6,925 pointsBadges:
    report
  • Denny Cherry
    Uh Brent, the button actually says "ADD TO DISCUSSION".
    66,360 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following