Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inserting Record into SQL from VFP App
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00405841
Message ID:
00405891
Vues:
41
>I've almost got it, but not quite. I've been able to insert a record if I use actual values, but not if I use variables. Here is the command I'm using that works and then what I want to do:
>
>sqlexec(gnConnHandle,"Insert into CQIPATIENTS (FacilityID, DeptID, PatNumber,LastName,FirstName) Values (1,1,'C11','Kelly','Kirk')")
>
>The above statement works, but I want to do the following:
>
>sqlexec(gnConnHandle,"Insert into CQIPATIENTS (FacilityID, DeptID, PatNumber,LastName,FirstName) Values (gnFacID,gnDeptID,gcPatNumber,lcLastName,lcFirst)")
>
>This one comes back and tells me:
>gnFacID is not permitted in this context. Only constants, expressions, or variables are allowed here. Column names are not permitted.
>
>I have also tried putting the @ in front of each variable, but to no availe

Kirk, you are close!

sqlexec(gnConnHandle,"Insert into CQIPATIENTS (DeptID, PatNumber,LastName,FirstName) Values (?gnDeptID,?gcPatNumber,?lcLastName,?lcFirst)")

Using the question mark in the SQLExec() command, VFP knows what you want. Your attempt didn't work because VFP sent all the string to SQLServer, which, of course, has no idea what gnFacID is!

Note: as I think you stated, FacilityID is an identity column, so you cannot put a value into it. SQLServer will take care of it. That is why I removed it from the SQLExec() command.

Hope this helps!
Sylvain Demers
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform