Article ID: 142568
Article Last Modified on 9/30/2003
* Connect to a SQL server using a predefined datasource.
xhandle = SQLCONNECT(DataSourceName, cUserID, cPassword)
IF xhandle > 0
WAIT WINDOW "Successful Connection. Handle = " + STR(xhandle)
ELSE
WAIT WINDOW "Bad connection"
=errhand()
RETURN
ENDIF
* Use the appropriate database.
x = sqlexec(xhandle,"use pubs")
IF x < 0
=errhand()
RETURN
ENDIF
* Create the default.
x = SQLEXEC(xhandle,"create default mystate as 'WA' ")
IF x < 0
=errhand()
RETURN
ENDIF
* Run a stored procedure to bind the default "mystate" to a
* specific column.
x = SQLEXEC(xhandle,"sp_bindefault mystate, 'authors.state' ")
IF x < 0
=errhand()
RETURN
ENDIF
* Each new row inserted will contain the value 'WA' for authors.state
* if a value is not supplied.
* Disconnect
x = SQLDISCONNECT(xhandle)
IF x < 0
=errhand()
RETURN
ENDIF
PROCEDURE errhand
=AERROR(myerror)
CLEAR
? 'An error has occurred.'
FOR n = 1 to 7
? myerror(n)
ENDFOR
= SQLDISCONNECT(xhandle)
RETURN
Additional query words: VFoxWin
Keywords: kbcode KB142568