Problema al insertar registro en base de datos access
Publicado por Toni (30 intervenciones) el 30/10/2014 16:00:36
Hola buenas tardes, estoy intentando realizar una insercion de un registro en una base de datos access con VB.NET y me da un error cuando intento ejecutarla. Yo creo que puede ser problema a la hora de escribir la cadena SQL con distintos tipos de datos (Strings y Doubles) y que por eso no se me ejecute.
Como error me sale : System.Data.OleDbException(0x80040E14) : Error de sintaxis en la intrucción INSERT INTO
pero soy inexperto en esto y no logro dar con la solución!
Podrian ayudarme por favor? Aqui les copio el codigo de mi funcion. GRACIAS DE ANTEMANO.
Function AjouterPipe(ByVal Product As String, ByVal UK As String, ByVal DRW As String, ByVal Description As String, ByVal KittingTime As Double, ByVal CuttingWiresTime As Double, ByVal CuttingCablesTime As Double, ByVal CableStrippingTime As Double, ByVal CrimpingTime As Double, ByVal TwistWiresTime As Double, ByVal MechanicalAssamblyTime As Double, ByVal SubAssamblyTime As Double, ByVal AssamblyTime As Double, ByVal ElectricalTestTime As Double, ByVal GlueClosingTime As Double, ByVal InsulationTestTime As Double, ByVal FoamingTime As Double, ByVal CleaningTime As Double, ByVal CheckTime As Double, ByVal PackagingTime As Double, ByVal TotalTime As Double) As Boolean
'2.CONEXION
Dim Conexion As New OleDb.OleDbConnection
Conexion.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nino\Documents\Visual Studio 2013\Projects\StandarTimeNewProduct 3\DataBaseCMRT.accdb;Persist Security Info =False"
'3.CADENA SQL
Dim CadenaSQL As String = "INSERT INTO " & Product & " (UK, DRW, Description, KittingTime, CuttingWiresTime, CuttingCablesTime, CableStrippingTime, CrimpingTime, TwistWiresTime, MechanicalAssamblyTime, SubAssamblyTime, AssamblyTime, ElectricalTestTime, GlueClosingTime, InsulationTime, FoamingTime, CleaningTime, 100%CheckTime,PackagingTime,TotalTime ) "
CadenaSQL = CadenaSQL + "VALUES ('" & UK & "', "
CadenaSQL = CadenaSQL + " '" & DRW & "', "
CadenaSQL = CadenaSQL + " '" & Description & "', "
CadenaSQL = CadenaSQL + " '" & KittingTime & "', "
CadenaSQL = CadenaSQL + " '" & CuttingWiresTime & "', "
CadenaSQL = CadenaSQL + " '" & CuttingCablesTime & "', "
CadenaSQL = CadenaSQL + " '" & CableStrippingTime & "', "
CadenaSQL = CadenaSQL + " '" & CrimpingTime & "', "
CadenaSQL = CadenaSQL + " '" & TwistWiresTime & "', "
CadenaSQL = CadenaSQL + " '" & MechanicalAssamblyTime & "', "
CadenaSQL = CadenaSQL + " '" & SubAssamblyTime & "', "
CadenaSQL = CadenaSQL + " '" & AssamblyTime & "', "
CadenaSQL = CadenaSQL + " '" & ElectricalTestTime & "', "
CadenaSQL = CadenaSQL + " '" & GlueClosingTime & "', "
CadenaSQL = CadenaSQL + " '" & InsulationTestTime & "', "
CadenaSQL = CadenaSQL + " '" & FoamingTime & "', "
CadenaSQL = CadenaSQL + " '" & CleaningTime & "', "
CadenaSQL = CadenaSQL + " '" & CheckTime & "', "
CadenaSQL = CadenaSQL + " '" & PackagingTime & "', "
CadenaSQL = CadenaSQL + " '" & TotalTime & "')"
'4.COMAND
Dim Comando As OleDbCommand = Conexion.CreateCommand()
Comando.CommandText = CadenaSQL
'5. EJECUTAR LA INSERCION
Try
Conexion.Open()
Comando.ExecuteNonQuery()
Conexion.Close()
Catch ex As Exception
If ex.ToString.Contains("valores duplicados") Then
MsgBox("El Producto este ya se encuentra introducido")
Else
MsgBox(ex.ToString)
End If
End Try
Return True
End Function
Como error me sale : System.Data.OleDbException(0x80040E14) : Error de sintaxis en la intrucción INSERT INTO
pero soy inexperto en esto y no logro dar con la solución!
Podrian ayudarme por favor? Aqui les copio el codigo de mi funcion. GRACIAS DE ANTEMANO.
Function AjouterPipe(ByVal Product As String, ByVal UK As String, ByVal DRW As String, ByVal Description As String, ByVal KittingTime As Double, ByVal CuttingWiresTime As Double, ByVal CuttingCablesTime As Double, ByVal CableStrippingTime As Double, ByVal CrimpingTime As Double, ByVal TwistWiresTime As Double, ByVal MechanicalAssamblyTime As Double, ByVal SubAssamblyTime As Double, ByVal AssamblyTime As Double, ByVal ElectricalTestTime As Double, ByVal GlueClosingTime As Double, ByVal InsulationTestTime As Double, ByVal FoamingTime As Double, ByVal CleaningTime As Double, ByVal CheckTime As Double, ByVal PackagingTime As Double, ByVal TotalTime As Double) As Boolean
'2.CONEXION
Dim Conexion As New OleDb.OleDbConnection
Conexion.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nino\Documents\Visual Studio 2013\Projects\StandarTimeNewProduct 3\DataBaseCMRT.accdb;Persist Security Info =False"
'3.CADENA SQL
Dim CadenaSQL As String = "INSERT INTO " & Product & " (UK, DRW, Description, KittingTime, CuttingWiresTime, CuttingCablesTime, CableStrippingTime, CrimpingTime, TwistWiresTime, MechanicalAssamblyTime, SubAssamblyTime, AssamblyTime, ElectricalTestTime, GlueClosingTime, InsulationTime, FoamingTime, CleaningTime, 100%CheckTime,PackagingTime,TotalTime ) "
CadenaSQL = CadenaSQL + "VALUES ('" & UK & "', "
CadenaSQL = CadenaSQL + " '" & DRW & "', "
CadenaSQL = CadenaSQL + " '" & Description & "', "
CadenaSQL = CadenaSQL + " '" & KittingTime & "', "
CadenaSQL = CadenaSQL + " '" & CuttingWiresTime & "', "
CadenaSQL = CadenaSQL + " '" & CuttingCablesTime & "', "
CadenaSQL = CadenaSQL + " '" & CableStrippingTime & "', "
CadenaSQL = CadenaSQL + " '" & CrimpingTime & "', "
CadenaSQL = CadenaSQL + " '" & TwistWiresTime & "', "
CadenaSQL = CadenaSQL + " '" & MechanicalAssamblyTime & "', "
CadenaSQL = CadenaSQL + " '" & SubAssamblyTime & "', "
CadenaSQL = CadenaSQL + " '" & AssamblyTime & "', "
CadenaSQL = CadenaSQL + " '" & ElectricalTestTime & "', "
CadenaSQL = CadenaSQL + " '" & GlueClosingTime & "', "
CadenaSQL = CadenaSQL + " '" & InsulationTestTime & "', "
CadenaSQL = CadenaSQL + " '" & FoamingTime & "', "
CadenaSQL = CadenaSQL + " '" & CleaningTime & "', "
CadenaSQL = CadenaSQL + " '" & CheckTime & "', "
CadenaSQL = CadenaSQL + " '" & PackagingTime & "', "
CadenaSQL = CadenaSQL + " '" & TotalTime & "')"
'4.COMAND
Dim Comando As OleDbCommand = Conexion.CreateCommand()
Comando.CommandText = CadenaSQL
'5. EJECUTAR LA INSERCION
Try
Conexion.Open()
Comando.ExecuteNonQuery()
Conexion.Close()
Catch ex As Exception
If ex.ToString.Contains("valores duplicados") Then
MsgBox("El Producto este ya se encuentra introducido")
Else
MsgBox(ex.ToString)
End If
End Try
Return True
End Function
Valora esta pregunta


0