vb.net - Syntax error with Date in sql query -


In my program, I change the date to date from the date of the date in the global variable My.Settings.date = DtpDate_do saving. Value.Date . I am using this date to compare date from my database but I am always getting a syntax error, irrespective of which I am changing. This is my query:

  cmd.CommandText = "SELECT ID, order_date command from WHERE order_date =" & amp; My.Settings.date & amp; "Order by ID DESC"   


The dates of my database are stored in dots in EU format - 17.2.2014 . Someone can provide me some help.

Never create your query in this way Always and without exception, use parameters This SQL-Injection Avoids both methods and ensures proper formatting of your parameters.

VB Sorry to know about Net, but it should be like this:

  cmd CommandText = "SELECT ID, order_date order by WHERE order_date = @DATE ORDER ID DESC" cmd.Parameters. AddWithValue ("@ Date", My.Settings.data)   

Explanation: Create your query again by using @ParamName as a placeholder for your parameter Transfer your criteria with the values ​​Make sure either apply a concrete typed value (i.e. no object) or / And otherwise supply the data type.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -