I have created a view in my database to get the desired result. The query is as follows,
Select *
from SignInEmployeeDetails
where EmployeeID = 1
and CONVERT(DATE, LateComingDate) >= CONVERT(DATE, '04/02/2015')
I tried running it in SQL Server Management Studio and it executes fine.
But when I include this query in my ASP.Net applicaiton I get no result but when I debug and see the query it is same as the above. My ASP.Net code is as follows,
Protected Sub BindSignInDetails()
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionStringName").ToString())
Dim comm As New SqlCommand(
"Select * from SignInEmployeeDetails where EmployeeID = " +
EmployeeID.ToString() +
" and CONVERT(DATE, LateComingDate) >= CONVERT(DATE, '" +
txtLateComingDate.Text.ToString() + "')", con)
con.Open()
Dim dr As SqlDataReader = comm.ExecuteReader()
If dr.Read() Then
txtFirstTimeIn.Text = dr("FirstTimeIn").ToString()
txtLateTimeDuration.Text = dr("LateTimeDuration").ToString()
End If
dr.Close()
con.Close()
End Sub
What can be the issue? Could anyone help me on this?
Edited:
I have updated my code to include parameterized query as follows,
cmd.Connection = con
cmd.CommandType = CommandType.Text
'representing type of command
cmd.CommandText = "Select * from SignInEmployeeDetails where EmployeeID = @EmployeeID and LateComingDate = @LateComingDate"
'adding parameters with value
cmd.Parameters.AddWithValue("@EmployeeID", EmployeeID.ToString())
cmd.Parameters.AddWithValue("@LateComingDate", txtLateComingDate.Text.ToString())
con.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.Read() Then
txtFirstTimeIn.Text = dr("FirstTimeIn").ToString()
txtLateTimeDuration.Text = dr("LateTimeDuration").ToString()
End If
dr.Close()
con.Close()
But still I don't get any results. What is the issue?