alejopereira12 Posted May 26, 2018 Share Posted May 26, 2018 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)" Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted May 27, 2018 Share Posted May 27, 2018 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") Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.