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?
Selecting values from database into combo box...
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'
This should get you started,
--blueb
- 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
--blueb
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.
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.
You've found PureBasic... now stick with it. You can do nearly everything in PB.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.
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
-
- New User
- Posts: 9
- Joined: Sun Nov 16, 2003 9:30 pm
- Location: Toowoomba, Australia
- Contact:
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.[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 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
TTFN
Stewart
-------------------------------------
Trying!, why that the first step to failure...
Stewart
-------------------------------------
Trying!, why that the first step to failure...