Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Inserting records to SQL Server
Message
From
30/10/2001 20:04:04
 
 
To
30/10/2001 19:51:07
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00574760
Message ID:
00575420
Views:
18
This message has been marked as the solution to the initial question of the thread.
Sergio,

See my corrections inserted below:

>Crescencio, I tried the code that you sent me.
>
>
>Here is the code:
>
>************************************************************************
>*-- jeinterface is a VFP table with a field called
>*-- batch_skey wich is character type.
>IF !USED('jeinterface')
> USE jeinterface IN 0
> SELECT jeinterface
>ELSE
> SELECT jeinterface
>ENDIF
>GO TOP
>*-- Create connection to SQL server
>nHan = SqlConnect("jeinterface")
>IF ( nHan = -1 )
> WAIT WINDOW 'failure of Connect'
>ENDIF
>
>SCAN
> lcBatchSkey =jeinterface.batch_skey
> nRes = SQLExec(nHan, "INSERT INTO jeinterface (batch_skey);
> Values('THIS IS A TEST') ")
> IF ( nRes = -1 )
> WAIT WINDOW 'failure of SQLExec' NOWAIT
> ENDIF
>ENDSCAN
>
>***************************************************************************
>
>
>
>The code above works fine but when I try to do the following :
>***************************************************************************
> lcBatchSkey =jeinterface.batch_skey
> nRes = SQLExec(nHan, "INSERT INTO jeinterface (batch_skey);
> Values(lcBatchSkey) ")
>****************************************************************************
nRes = SQLExec(nHan, "INSERT INTO jeinterface (batch_skey);
          Values(" + lcBatchSkey + ") ")
If the batch_skey field is char, varchar or date you should include single quotes before and after the concatenated variable. Basically you pass a string to SQLExec to be executed on the server. What is happening here is that SQL Server has no knowledge of lcBatchsKey.

If you are going to be adding a lot of records at a time it might be a good idea to use SqlPrepare() for improving performance. It would go something like this:
nHan = SqlConnect("jeinterface")
IF ( nHan = -1 )
   WAIT WINDOW 'failure of Connect'
ENDIF

lcBatchSkey = 'THIS IS A TEST'
nRes = SqlPrepare(nHan, "INSERT INTO jeinterface (batch_skey) Values(?lcBatchSkey)")
SCAN
   lcBatchSkey=jeinterface.batch_skey
   nRes = SQLExec(nHan)
   IF ( nRes = -1 )
   	  WAIT WINDOW 'failure of SQLExec' NOWAIT
   ENDIF
ENDSCAN
I didn't tested this for syntax, but should give you the general idea. Hope this helps.

>
>The above insert does not work. So the question is how can I insert values from the jeinterface visual foxpro table to the SQL server table.
>
>
>Any clue of what might be the problem.
>
>Thanks,
>Sergio
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform