I need help with inserting a record into an MS-Access table.
All fields for the table were defined as text fields.
My program would not insert a record into the MS-Access table.
Portions of the code were copied from postings found here in the forum.
I am currently using PB v4.1
Shown below is the insert routine I'm using
Code: Select all
Procedure RecordResults()
;**********************
;* Open History Table *
;**********************
File$ = "StudentRecord.mdb"
EXT.s=UCase(GetExtensionPart(File$))
dbStatus=Makeconnection("Microsoft Access Driver (*.mdb)","Server=SomeServer; Description=Description For Purebasic MDB-ODBC;DSN=PureBasic_DSN;DBQ="+File$+";UID=Rings;PWD=Siggi;")
If UseODBCDatabase() = 0
MessageRequester("Error", "Can't initialize Database (ODBC v3 or better) environment", 0)
End
EndIf
; Open an ODBC database
User$=""
Password$=""
#Database=1
dbStatus = OpenDatabase(#Database, "PureBasic_DSN", User$, Password$)
;*********************
;* Insert New Record *
;*********************
If dbStatus
catNum.s = Str(categoryNumber)
If Len(catNum) = 1
catNum = "0" + catNum
EndIf
testDate.s = FormatDate("%yyyy-%mm-%dd %hh:%mm", Date())
modeStr.s = Str(mode)
itemCtStr.s = Str(itemCt)
scoreStr.s = Str(correct)
SQLstr.s ="insert into history (category, testdate, testmode, itemct, score) values ("
SQLstr = SQLstr + Chr(34) + catNum + Chr(34) + "," + Chr(34) + testdate + Chr(34) + "," + Chr(34) + modeStr + Chr(34) + "," + Chr(34) + itemCtStr + Chr(34) + "," + Chr(34) + scoreStr + Chr(34) + ");"
Debug SQLstr
DatabaseQuery(#Database, SQLstr)
EndIf
;***********************
;* Close History Table *
;***********************
DeleteConnection("Microsoft Access Driver (*.mdb)","PureBasic_DSN")
EndProcedure
Code: Select all
insert into history (category, testdate, testmode, itemct, score) values ("22","2008-06-15 23:06","0","150","0")
I had also tried using
Code: Select all
DatabaseUpdate(#Database, SQLstr)
Anyone have an idea of what's wrong with my code and how to solve this problem?