Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safe DateTime in a T-SQL INSERT statement

Been running in problem lately with using a DateTime in a T-SQL INSERT INTO statement. Work fine on one machine but might not work on another and I guess this has to do with locale settings.

So if I have DateTime variable what is the safe way of using that in a SqlStatement string that it will always work regardless on local system settings?

Thanks

like image 984
StefanE Avatar asked Jan 19 '23 16:01

StefanE


1 Answers

Use parameterized INSERT query.

Most likely, your code is assembling the SQL command string. That also makes your code vulnerable to SQL Injection.

like image 103
Adriano Carneiro Avatar answered Jan 27 '23 05:01

Adriano Carneiro