AUTODEFINE "Off"

DEF path, filename, fname, tmp:STRING
DEF hStmt:UINT
DEF pDB:POINTER
DEF lname[300],iStmt[500]:ISTRING
DEF i:INT

path = GETSTARTPATH
filename = "test.mdb"

OPENCONSOLE

opendatabase()

IF hStmt THEN dbFreeSQL(hStmt)
dbDisconnect(pDB)

PRINT
PRINT "Done ",
INPUT tmp

CLOSECONSOLE

END

SUB opendatabase()
	DELETEFILE PATH+filename
	hStmt=NULL
	pDB=dbConnect("Microsoft Access Driver (*.mdb, *.accdb)",PATH+filename,"",0)
IF pDB=NULL
	PRINT "Create DB"
'Couldn't open so try creating
	dbCreateMDB(PATH+filename)
	pDB=dbConnect("Microsoft Access Driver (*.mdb, *.accdb)",PATH+filename,"",0)
	IF pDB<>NULL
'Create Product Description table
		iStmt="CREATE TABLE Customers (recID integer primary key, lname LONGTEXT, fname char(200))"
		hStmt=dbExecSQL(pDB,iStmt)
'Check for errors
		IF LEN(dbGetErrorCode(hStmt))
			MESSAGEBOX 0,"("+STR$(__LINE__)+") "+dbGetErrorText(hStmt)+"\n"+iStmt,dbGetErrorCode(hStmt)
			RETURN
		ENDIF
		dbFreeSQL(hStmt)
		hStmt=NULL

'Insert Product 
		iStmt="INSERT INTO Customers (recID) VALUES(101)"
		hStmt=dbExecSQL(pDB,iStmt)
'Check for errors
		IF LEN(dbGetErrorCode(hStmt))
			MESSAGEBOX 0,"("+STR$(__LINE__)+") "+dbGetErrorText(hStmt)+"\n"+iStmt,dbGetErrorCode(hStmt)
			RETURN
		ENDIF
		dbFreeSQL(hStmt)
		hStmt=NULL

		fname = "123456789 "
		lname = ""
		FOR i = 1 TO 29
			lname += fname
		NEXT i
		fname = "The great bobble head caper of Northern America - "
		fname += fname

		PRINT
		PRINT "(", len(fname), ") ", fname
		PRINT
		PRINT "(", len(lname), ") ", lname

		iStmt="UPDATE customers SET lName=?,fName=? WHERE recID=101"
		hStmt=dbPrepareSQL(pDB,iStmt)
		dbBindParameter(hStmt,1,lName,300)  '<------------------- Here!
		dbBindParameter(hStmt,2,fName,200)

		dbExecute(hStmt)
		IF LEN(dbGetErrorCode(hStmt))
' <--------- Error message here
			MESSAGEBOX 0,"("+STR$(__LINE__)+") "+dbGetErrorText(hStmt)+"\n"+iStmt,dbGetErrorCode(hStmt)
		ENDIF
		dbFreeSQL(hStmt)
		hStmt=NULL

	ENDIF
ENDIF
ENDSUB
