Sign in to follow this  
alejopereira12

Write an alphanumeric to SQL SERVER

Recommended Posts

I'm trying to write an alphanumeric entry to a DB on SQL SERVER, however the program show me this error: Unable to execute: HY010: Conexion_BD Line 10 - Uncaught error in sequence Conexion_BD. The Line 10 looks like this:

db.Execute(dbase, "INSERT INTO Alival_Descargue.dbo.Estados_PLC(Fecha,VolumenRemisionado,Temperatura,Placa) VALUES (CONVERT(datetime,GETDATE(),20),"+Volumen_remisionado[0]+","+TemperaturaLlegada[0]+","+Placa[0]+")")

The thing is that the code works correctly when i'm using the other channels ( Volumen_remisionado, TemperaturaLlegada) but when i add the "Placa" channel, the sequence stop working.

The data type on channel is "String" and in the database is "varchar(7)" 

 

 

Share this post


Link to post
Share on other sites

You have to put quotes around any string literals in your SQL statement.  So at the end it is:

',"' + Placa[0]+'")')

It's hard to see here, but I replaced the double quotes with single quotes and put double quotes inside.  DAQFactory treats them the same as long as they are paired up, but I don't know if SQL SERVER supports single quotes.

I usually find it helpful to copy my db.execute() line to another line before it, and remove it down to just a ? (print) statement:

? "INSERT INTO Alival_Descargue.dbo.Estados_PLC(Fecha,VolumenRemisionado,Temperatura,Placa) VALUES (CONVERT(datetime,GETDATE(),20),"+Volumen_remisionado[0]+","+TemperaturaLlegada[0]+","+Placa[0]+")"

Then you will see the actual SQL statement that you generated in the command alert window.  You can even copy / paste it into a SQL command line and let SQL Server tell you exactly where the error is.  But I know it will be the lack of quotes, as your's will evaluate to something like:

INSERT INTO Alival_Descargue.dbo.Estados_PLC(Fecha,VolumenRemisionado,Temperatura,Placa) VALUES (CONVERT(datetime,GETDATE(),20),1,2,MyString)

where you really want:

INSERT INTO Alival_Descargue.dbo.Estados_PLC(Fecha,VolumenRemisionado,Temperatura,Placa) VALUES (CONVERT(datetime,GETDATE(),20),1,2,"MyString")

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this