sql server - Conversion failed: SqlParameter and DateTime -


I'm changing old with SqlParameters, weak SqlCommands, but get a SqlException:

< p> system .Data.SqlClient.SqlException { "conversion failed when converting character date string."}

the sqlCommand.ExecuteScalar :

< Pre> dim sqlString string = _ "SELECT TOP 1" & amp; _ "FSL" & amp; _ "FROM" & amp; _ "TabData ASD" & amp; _ "WHERE" & amp; _ "D.SSN_Number = '@SSN_Number'" & amp; _ "And Diffproduct type = 1" & amp; _ "And D.Repair_Completion_Date & gt; '@Repair_Completion_Date'" & amp; _ "Order bye" & amp; Try Dim obj sqlCommand as the object dim sql command as "D.Repair_Completion_Date ASC" sqlCommand = New SqlCommand (sqlString, Common.MyDB.SqlConn_RM2) sqlCommand.CommandTimeout = 120 sqlCommand.Parameters.AddWithValue ("@SSN_Number" , myClaim.SSNNumber) sqlCommand .Parameters.AddWithValue ( "@ Repair_Completion_Date", myClaim.RepairCompletionDate) If Common.MyDB.SqlConn_RM2.State & lt; & Gt; System.Data.ConnectionState.Open then Common.MyDB.SqlConn_RM2.Open () obj = sqlCommand.ExecuteScalar () catch prior exception dim debug As String = (Common.MyDB.SqlConn_RM2.Close in ex.ToString end) end Try

myClaim.RepairCompletionDate is a SQLDateTime. Do I have to remove quotation marks in sqlString to compare the date column? But then I do not get an exception but wrong results

Yes, quotes should be removed. You should not have quotes around the parameters in T-SQL - not even using string. Therefore, you should remove the @SSN_Number and @Repair_Completion_Date around the quote.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -