I have the following line var examNumber = testExamData.examDetails.examNumber;
and its value is ABX0916
var examNumber = testExamData.examDetails.examNumber;
con = new SqlConnection(connectionString);
con.Open();
cmd = new SqlCommand("UPDATE [dbo].[Exams_Data] SET [Exam_Date] = DATEADD(DAY, +90, GETDATE())" +
"WHERE [Status_ID] = 2 AND [Exam_Number] = " + @"" + examNumber + @"", con);
dr = cmd.ExecuteReader();
In the above code, var examNumber
is ABX0916.
Then in cmd, the value for commandText is coming as below:
"UPDATE [dbo].[Exam_Data] SET [Exam_Date] = DATEADD(DAY, +90, GETDATE())WHERE [Status_ID] = 2 AND [Exam_Number] = ABX0916".
Since ABX0916 is a string, i want it to be in double quotes in the SQL to be executed.
Below is the command i want to be execute (with ABX0916 in double quotes)
UPDATE [dbo].[Exam_Data] SET [Exam_Date] = DATEADD(DAY, +90, GETDATE())WHERE [Status_ID] = 2 AND [Exam_Number] = "ABX0916"
How do i correctly escape this @"" + examNumber + @""
to achieve that?