Open, Read, Write/Update to a Microsoft SQL Server database.

Started by nrh7, August 27, 2024, 09:03:29 PM

Previous topic - Next topic

nrh7

Greetings again!, Been a while, this project has been renewed and I still need to figure out this part.
The whole point of thise project is to use iNomands to make a sort of webapp that connects to the client database on SQL Server.

These are a few things I tried, because actually the urgent thing now is to UPDATE a record rather than make a new entry (for now)

The code goes like:

LET V1$="BLAH BLAH"
LET V2$="3M115"
OPEN (CHAN,OPT=";USER=pvx;PSWD=pvx123@123@;Connect='Provider=SQLOLEDB;';CONCURRENCY=LOCK;EXTROPT=(UPDLOCK)")"[ado]SADI\SQLEXPRESS"

((EDIT: does that "UPDLOCK" line in the previous line have anything to do with preventing updating records?))



These attempts failed trying the INSERT INTO and UPDATE

WRITE RECORD (CHAN,KEY="!INSERT INTO [WMPOS].[dbo].[D_INVENTORY] ITEM_NAME ='"+V1$+" ' WHERE ITEM_ID_ORIGINAL ='"+V2$+"'")

WRITE RECORD (CHAN,KEY="!UPDATE [WMPOS].[dbo].[D_INVENTORY] SET ITEM_NAME ='"+V1$+" ' WHERE ITEM_ID_ORIGINAL ='"+V2$+"'")

Any hints on how to make that proper line code?

Thanks a bunch!!!

nrh7

This one works:

READ (CHAN,KEY="!UPDATE [WMPOS].[dbo].[D_INVENTORY] SET ITEM_NAME = 'BLEH' WHERE ITEM_ID_ORIGINAL = '3M115'")

But it gives me an END of file error afterwards, which I think I can just skip it with an extra code on errors.

Devon Austen

These:

WRITE RECORD (CHAN,KEY="!INSERT INTO [WMPOS].[dbo].[D_INVENTORY] ITEM_NAME ='"+V1$+" ' WHERE ITEM_ID_ORIGINAL ='"+V2$+"'")

WRITE RECORD (CHAN,KEY="!UPDATE [WMPOS].[dbo].[D_INVENTORY] SET ITEM_NAME ='"+V1$+" ' WHERE ITEM_ID_ORIGINAL ='"+V2$+"'")

Should be:

WRITE RECORD (CHAN)"INSERT INTO [WMPOS].[dbo].[D_INVENTORY] ITEM_NAME ='"+V1$+" ' WHERE ITEM_ID_ORIGINAL ='"+V2$+"'"

WRITE RECORD (CHAN)"UPDATE [WMPOS].[dbo].[D_INVENTORY] SET ITEM_NAME ='"+V1$+" ' WHERE ITEM_ID_ORIGINAL ='"+V2$+"'"

The key="!<SQL>" syntax is for reads not writes. For writes you just pass in the SQL as what you are writing.

You read with a key= will work but since it does not return data you do after to ignore the error. I think using a write is better here since it doesn't try to read any response back.
Principal Software Engineer for PVX Plus Technologies LTD.

nrh7