• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

Insert redords in SQL from Foxpro

I want to populate a SQL Server 2008 database table with records for test purposes. I use Foxpro 9.0 sp2 and have tried with this code, that unfortunately don't work. The Sqlexec line returns -1 and nothing is stored in the table. What am I doing wrong?

close databases all
clear
cConnstr = 'DSN=Demo;Description=Demo;UID=myopid;' + ;
      'Trusted_Connection=Yes;APP=Microsoft Visual FoxPro;' + ;
      'WSID=MYPCNAME;DATABASE=Demo;'
      
nHnd = Sqlstringconnect(cConnstr)

for ii=1 to 100
      cAccount = Transform(Int(ii + 1000))
      cAccountName = 'Name: ' + cAccount
      ? cAccount, cAccountName
      Sqlexec(nHnd, 'insert into Trans  (Account, AccountName) values (cAccount, cAcoountName)')
      ?? Sqlcommit(nHnd)
next

Sqldisconnect(nHnd)
0
krhag
Asked:
krhag
  • 2
  • 2
2 Solutions
 
wcsoctuCommented:
Put a question mark in front of cAccount and cAccountName.
Sqlexec(nHnd, 'insert into Trans  (Account, AccountName) values (?cAccount, ?cAccountName)')

In your example cAccountName is misspelled also.
0
 
pcelbaCommented:
Execute following command immediatelly after SQLEXEC which returns -1

? AERROR(laErr)

laErr is an array and it should contain extended error info from ODBC driver. You may display this info by:

DISPLAY MEMOTY LIKE laErr

BTW, the Sqlcommit(nHnd)  is not necessary in your case because you did not open any transaction.
0
 
pcelbaCommented:
The questionmark should probably help.
0
 
krhagAuthor Commented:
Thanks, I'll try this. The misspelling is a typo only here...
0
 
krhagAuthor Commented:
Thanks... I should have found it myself... but this saved lots of time :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now