Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ODBC -- inserting records into SQL Server
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
00998178
Message ID:
00998182
Vues:
17
This message has been marked as a message which has helped to the initial question of the thread.
>I am trying to insert records into SQL Server from Fox via ODBC, and this should be a simple task (I've been selecting data without problem), but I'm having no luck so far.
>
>My coding (simplified) is:
>
> CREATE DATABASE test
> CREATE CONNECTION MyODBC DATASOURCE "purges_tmp" USERID "taskadmin" PASSWORD "taskadmin"
> pn1 = SQLConnect( pc_dsrc, pc_uid, pc_uid )
> DISPLAY CONNECTIONS
> SELECT dlvm
> pc_acct = acct_no
> pc_data = dataline
> pn_sqle = SQLExec(pn1, "INSERT vz_notes (dbacct, dataline) VALUES(pc_acct, pc_data)")
> =SQLDISCONNECT( pn1)
> DELETE CONNECTION MyODBC
>
>I am consistently getting a return of 1 for the SQLConnect, and (-1) on the SQLExec. Is my syntax wrong, or could the SQL Server table be locked to updates? What am I missing here?

You can do that 2 ways:

1. Build the Insert string before SQLEXEC
        sqlInsert = "INSERT INTO INSERT vz_notes (dbacct, dataline) VALUES ("+TRANSFORM(acct_no)+", "+TRANSFORM(dataline)+")
	pn_sqle = SQLExec(pn1, sqlInsert)
But that way You shuold think about Types of data you insert.

2. Send the vaules as a parameters:
   pc_acct = acct_no
   pc_data = dataline
   pn_sqle = SQLExec(pn1, "INSERT vz_notes (dbacct, dataline) VALUES (?pc_acct, ?pc_data)")
BTW it is always a good idea to check what happens after insert. To see if that insert (or any other SQLEXEC() command is successful:
   pc_acct = acct_no
   pc_data = dataline
   pn_sqle = SQLExec(pn1, "INSERT vz_notes (dbacct, dataline) VALUES (?pc_acct, ?pc_data)")
   IF pn_sqle < 0
      AERROR(aErr)
      DISPLAY MEMO LIKE aErr
   ENDIF
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform