How to insert date data from pc to sql

1

I have a TextBox that captures the date of the machine using this code:

  

TextBox1.Text = DateTime.Now.ToString ("dd / MM / yyyy")

I have a field in my sql table named Date of type date

When I try to insert the data

  

insert into tbltest (date) values ('"& TextBox1.Text &"') ", with)

I get this error:

    
asked by Samuel Ignacio Susana Confesor 24.07.2017 в 21:56
source

1 answer

1

You have a data type error, you receive the date as text and you need to convert it to the Date type to insert it into your database.

Dim MiFecha as date
MiFecha = Date.Parse(TextBox1.Text)

Then you use the variable in your insert

insert into tblprueba (fecha) values('" & MiFecha &"')",con)

Maybe you have to change the format, I can not try it right now, but it should work;)

    
answered by 24.07.2017 / 23:04
source