For example, I have an Access database (db1.mdb) that is intact and useable from Access. But I cannot open it with PB.
The db1.db file exists in the correct directory, I am certain of the user id and password entries, but I cannot open it. I have manually created the DSN.
The following code (modified from another post to make current) will not open the file.
Code: Select all
;
; Little Database Explorer written by AlphaSND
;
; Fully Resizeable GUI - Easy to do
;
Procedure ResizeGUI()
ResizeGadget(0, 10, 10, WindowWidth()-25, WindowHeight()-75)
ResizeGadget(1, 10, WindowHeight()-51, 100, 22)
ResizeGadget(2, 110, WindowHeight()-55, WindowWidth()-175, 22)
ResizeGadget(3, WindowWidth()-65, WindowHeight()-55, 50, 22)
EndProcedure
Procedure WindowCallback(Window, Message, wParam, lParam)
If Message = #WM_SIZE
ResizeGUI()
ProcedureReturn -1 ; Tell PureBasic internal handler than the message is already processed
EndIf
EndProcedure
If InitDatabase() = 0
MessageRequester("Error", "ODBC v3.0+ can't be opened.", 0)
End
ElseIf OpenDatabase(0, "db1.mdb", "admin", "")
If OpenWindow(0, 0, 100, 640, 480, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget| #PB_Window_MaximizeGadget, "PureBasic DataBase Explorer - v1.0")
If CreateGadgetList(WindowID())
ListIconGadget(0, 0, 0, 0, 0, "",0)
TextGadget (1, 0, 0, 0, 0, "SQL Request:")
StringGadget (2, 0, 0, 0, 0, "Select * from lcr_employe")
ButtonGadget (3, 0, 0, 0, 0, "Go !")
ResizeGUI()
EndIf
SetWindowCallback(@WindowCallback())
ActivateGadget(2)
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_EventGadget
Select EventGadgetID()
Case 3
Gosub ExecuteQuery
EndSelect
EndSelect
Until EventID = #PB_EventCloseWindow
EndIf
Else
MessageRequester("Info","Cannot open database",#MB_ICONINFORMATION)
EndIf
End
ExecuteQuery:
#LVM_SETEXENDEDLISTVIEWSTYLE = #LVM_FIRST+54
#LVS_EX_GRIDLINES = 1
#LVS_EX_FULLROWSELECT = $20
If DatabaseQuery(GetGadgetText(2))
FreeGadget(0)
*LI = ListIconGadget(0, 10, 10, WindowWidth()-20, WindowHeight()-75,DatabaseColumnName(1), 80)
SendMessage_(*LI, #LVM_SETEXENDEDLISTVIEWSTYLE, #LVS_EX_GRIDLINES, -1)
SendMessage_(*LI, #LVM_SETEXENDEDLISTVIEWSTYLE, #LVS_EX_FULLROWSELECT, -1)
NbDatabaseColumns = DatabaseColumns()
Dim ColumnType.b(NbDatabaseColumns)
ColumnType(1) = DatabaseColumnType(1)
For k=2 To NbDatabaseColumns
AddGadgetColumn(0, k, DatabaseColumnName(k), 80)
ColumnType(k) = DatabaseColumnType(k)
Next
CurrentLine = 0
While (NextDatabaseRow())
Content$ = ""
For k=1 To NbDatabaseColumns
Select ColumnType(k)
Case 1
Content$+Str(GetDatabaseLong(k))
Case 2
Content$+GetDatabaseString(k)
Case 3
Content$+StrF(GetDatabaseFloat(k),10)
Default
Content$+"UNKNOW"
EndSelect
Content$+Chr(10)
Next
AddGadgetItem(0, CurrentLine, Content$, 0)
CurrentLine+1
Wend
Else
MessageRequester("Error", "Bad Query", 0)
EndIf
Return
Terry


