Article ID: 142920
Article Last Modified on 10/15/2003
* Establish connection to an existing datasource define to a SQL Server 6.0
* database.
xhandle = sqlconnect()
IF xhandle > 0
WAIT WINDOW "Successfull Connection. Handle = "+str(xhandle)
ELSE
WAIT WINDOW "Bad connection."
=errhand()
RETURN
ENDIF
* Create a table called Invoice and define the Identity property for the
* Invoice_no column - assuming that a table called invoice does not already
* exist.
x = SQLExec(xhandle,"Create table invoice (invoice_no INT" + ;
"identity(1000,1),customer varchar(25),;
amount money, inv_date datetime)")
IF x < 0
=errhand()
RETURN
ELSE
WAIT WINDOW "Table created successfully"
ENDIF
* Insert some new invoices.
x = SQLExec(xhandle,"Insert invoice (customer,amount,inv_date)" + ;
" Values('Brown & Assoc.',$40000,'01/01/96' )")
IF x < 0
=errhand()
RETURN
ENDIF
x = SQLExec(xhandle,"Insert invoice (customer,amount,inv_date)" + ;
"Values('Jones Inc.',$90000,'01/01/96' ) ")
IF x < 0
=errhand()
RETURN
ENDIF
x = SQLExec(xhandle,"Insert invoice (customer,amount,inv_date)" + ;
"Values('Golden Hedge',$25000,'01/01/96' )")
IF x < 0
=errhand()
RETURN
ENDIF
x = SQLExec(xhandle,"Insert invoice (customer,amount,inv_date)" + ;
"Values('CPUs R Us',$50000,'01/01/96' )")
IF x < 0
=errhand()
RETURN
ENDIF
* Check the values inserted.
x = SQLExec(xhandle,"Select * from invoice","Invoice")
IF x < 0
=errhand()
RETURN
ENDIF
SELECT Invoice
GO TOP
BROWSE
* Disconnect.
x = SQLDisconnect(xhandle)
IF x < 0
=errhand()
RETURN
ENDIF
* Error Handling Procedure
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 KB142920