Discussion:
Insert into sqlserver
(too old to reply)
dfranklyn
2005-09-01 15:24:54 UTC
Permalink
I am trying to insert a record into sqlser 2000/2005. I can query and update
existing records but not insert. I don't get an error on the command but
nothing is posted to the table. My code looks like this

<begin code>
#DEFINE SQL_NAME "devsql"
#DEFINE SQL_UID ""
#DEFINE SQL_PWD ""
*~~~~~~~~~~~

LOCAL lcSQLConnStr, ;
lnSQLConnHandle, ;
lnSQLExecSuccess

lcSQLConnStr = "DRIVER={SQL Server};SERVER=" + SQL_NAME + ;
";DATABASE=MEMBERSHIP;UID=" + SQL_UID + ";PWD=" + SQL_PWD

lnSQLConnHandle = SQLSTRINGCONNECT(lcSQLConnStr)
IF lnSQLConnHandle < 1
LOCAL laErrArray[1]
AERROR(laErrArray)
WAIT WINDOW "Unable to connect:" + CHR(13) + laErrArray[3]
RETURN .F.
ENDIF

SET STEP ON


LOCAL inmemnumb as String
inmemnumb = '1234567'

lnconn=SQLCONNECT('devsql')

lnSQLExecSuccess = SQLEXEC(lnSQLConnHandle, "insert into
newmemb(id,local,pri_loc,folio,lastname,f_init);
values('1234567','0495','0000','T''ALDRIDGE','L')")

lnSQLExecSuccess = SQLEXEC(lnSQLConnHandle, "SELECT * from newmemb where id
= ?inmemnumb ", "RESULTS")

SQLDISCONNECT(lnSQLConnHandle)

IF SELECT("RESULTS") > 0
SELECT RESULTS
BROWSE NOWAIT
ENDIF
<end code>

Can anyone tell me why the insert is not working?????

dfw
Cindy Winegarden
2005-09-01 20:44:43 UTC
Permalink
Hi DFranklyn,

Usually news clients break up long lines, so it's hard to tell where your
line breaks actually are, it appears that there's a line break in your
Insert statement and none in your Select statement. You've got a line break
in the middle of a quoted string in your Insert statement. You'd be better
off concatenating two shorter strings such as:

lnSQLExecSuccess = ;
SQLEXEC(lnSQLConnHandle, ;
"insert into newmemb(id,local,pri_loc,folio,lastname,f_init) " + ;
"values('1234567','0495','0000','T''ALDRIDGE','L')")

Also, it looks like you're missing a comma between the two single quotes
between T and ALDRIDGE.
--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
***@msn.com www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden
Post by dfranklyn
I am trying to insert a record into sqlser 2000/2005. I can query and update
existing records but not insert. I don't get an error on the command but
nothing is posted to the table. My code looks like this
lnSQLExecSuccess = SQLEXEC(lnSQLConnHandle, "insert into
newmemb(id,local,pri_loc,folio,lastname,f_init);
values('1234567','0495','0000','T''ALDRIDGE','L')")
lnSQLExecSuccess = SQLEXEC(lnSQLConnHandle, "SELECT * from newmemb where id
= ?inmemnumb ", "RESULTS")
Loading...