Page 1 of 1

Selecting values from database into combo box...

Posted: Sat Feb 26, 2005 2:48 pm
by Aiown
Hi all,

I am new to PureBasic. I have been working on Access databases, and now I'd like to re-write my applications in Purebasic with Firebird database backend. However, I cannot find good ODBC tutorials, and I got stuck right at the beginning.

I want to query the login table for username and display it in a combo dropdown list.

Can anyone help me, please?

Posted: Sat Feb 26, 2005 6:39 pm
by blueb
I assume you've gotten this far:
- Firebird server is up and running
- you've installed Firebird ODBC
(see: http://www.ibphoenix.com/main.nfs?a=ibp ... bp_60_odbc)

- Setup a new DNS using ODBC Data Source Administrator (Windows provides this tool) and the Firebird example database called EMPLOYEE.FDB

- I've made a sample PureBasic program that uses this file ( I've named my DNS file 'EmployeesINeed'

Code: Select all

If InitDatabase() 
   If OpenDatabase(0,"EmployeesINeed","SYSDBA","masterkey") ; "Admin=SYSDBA","User=masterkey" - these are default settings for Firebird)
   
      Result = DatabaseQuery("SELECT * FROM Customer;")  ; Select * from Customer table in Employees.fdb
     Debug  DatabaseColumnName(0) ; Return the name of the first column 

      If Result
         While NextDatabaseRow() 
            Debug GetDatabaseString(0)   ; Return information from the first column - You should see Customer ID's
          Wend 
       EndIf
    Else
      Debug "Can't open database"
    EndIf 
EndIf
This should get you started,
--blueb

Posted: Sat Feb 26, 2005 11:06 pm
by Aiown
Thank you, it worked, now I have to figure out how to pass the returned values to the combo and how to compare the entered password to the one in the table.

Sorry, I am new to PureBaseic and the tutorials only cover the very basic stuff. Is there anything more advanced out there?

Posted: Sat Feb 26, 2005 11:16 pm
by Aiown
OK, I found a way to add the usernames to the combo, but every time I click on the combo they are added again and again.

Here is the code:
________________
Init_PVDynamic()
XIncludeFile "frmLogin_Constants.pb"
XIncludeFile "frmLogin_Windows.pb"


Procedure WindowCallback(WindowID,Message,wParam,lParam)
ReturnValue=#PB_ProcessPureBasicEvents
If Message=#WM_CTLCOLORSTATIC Or Message=#WM_CTLCOLOREDIT Or Message=#WM_CTLCOLORLISTBOX
ReturnValue=PVDynamic_ColorGadget(lParam,wParam)
EndIf

ProcedureReturn ReturnValue
EndProcedure

;-Main Loop
If Window_frmLogin()
SetWindowCallback(@WindowCallback())

quitfrmLogin=0
Repeat
EventID=WaitWindowEvent()
Select EventID
Case #PB_Event_CloseWindow
If EventWindowID()=Window_frmLogin
quitfrmLogin=1
EndIf

Case #PB_Event_Gadget
Select EventGadgetID()
Case Gadget_frmLogin_cmbUsername
If InitDatabase()
If OpenDatabase(0,"CraneHire_Firebird","bela","Ai24Own")
Result = DatabaseQuery("SELECT username FROM Login")
If Result
While NextDatabaseRow()
Debug GetDatabaseString(0)
AddGadgetItem(Gadget_frmLogin_cmbUsername, -1, GetDatabaseString(0))
Wend
EndIf
EndIf
EndIf
Case Gadget_frmLogin_password
Case Gadget_frmLogin_btnOK
Case Gadget_frmLogin_btnExit
quitfrmLogin=1
EndSelect

EndSelect
Until quitfrmLogin
CloseWindow(Window_frmLogin)
EndIf
End
______________

Could you tell me if PureBasic is be suitable to write such applications that can be created in Access 2000 up, or shall I look for a more powerful language. I don't really want to go the C++/Java/C# way, I want something like PureBasic - cross platform and fast to develop in.

Posted: Sun Feb 27, 2005 6:05 pm
by blueb
Could you tell me if PureBasic is be suitable to write such applications that can be created in Access 2000 up, or shall I look for a more powerful language. I don't really want to go the C++/Java/C# way, I want something like PureBasic - cross platform and fast to develop in.
You've found PureBasic... now stick with it. You can do nearly everything in PB.

In cases where a PureBasic command cannot be found, you can generally find a Windows API command and create you own function (I'm assuming you are using the Windows version, since you mentioned Access 2000).

With PureBasic, ODBC and SQL, you should have no problems although Access does not follow SQL-92 standards exactly.

[opinion]
Personally I use PBDev (www.hellobasic.com to try the demo) for my development work. It's not only a Visual Designer (l see you used PureVision) but a total environment that adds event programming and is more WYSIWYG.
[/opinion]

Regards,
blueb

Posted: Tue Mar 01, 2005 2:58 am
by whiteside
[opinion]
Personally I use PBDev (www.hellobasic.com to try the demo) for my development work. It's not only a Visual Designer (l see you used PureVision) but a total environment that adds event programming and is more WYSIWYG.
[/opinion]
I fully agree, I have both pbDEV and PureVision. I am now using pbDEV for most of my Application development, this product allows me structure my Corporate style program development in a more orderly manner.

I recommend that people take a good look at this tool.

It is constantly being upgraded to meet the new versions of PB and the support is excellent, my requests for improvements have always be answered within days.

TTFN
Stewart