Help with this string to save in SQL

0

Could you help me find the error in this string, I'm using Visual Basic

INSERT INTO PRODUCTOS (CodigoProducto,Nombre,Compra,Venta,Stok,Fecha,Impuesto,idCategoria,idProveedor) 
 VALUES (" & ID & ",' " & nombre & " ',' " & Compra & " ',' " & Venta & " ',' " & Stok & " ',' " & Fecha & " ', " & Impuesto & ",' " & Categoria & " ',' " & Proveedor & " ')

In the Date section I get this error: conversion failed when converting character string to smalldatetime data type in sql server

My table is as follows:

varchar Product Code (12)

Name varchar (50)

Buy money

Money Sale

Stok int

Date smalldatetime

Tax float

idCategoria int

idProvider int

    
asked by Jeffry 17.03.2018 в 04:39
source

1 answer

0

I recommend you use datetime2 (7) for the date, and to save the data from visual basic you could use a string.Format, which converts the value of the objects into strings according to the specified formats and inserts them into another chain.

Example:

Dim cmd As String = String.Format("insert into productos (valor1,valor2) values ('{0}','{1}')", var1, var2)

You can do it with all the values you want. Greetings

    
answered by 17.03.2018 в 07:53