Hi,

I'm adding day shift column where current month (I'm using datetimepicker for extracting month from it )
but getting this error

Conversion failed when converting date and/or time from character string

Here is the code

Dim str10 As String = "Select COUNT(DayShift) FROM Attendance WHERE AttendanceStatus = 6 AND AttendanceDate ='" & Month(DateTimePicker1.Text) & "' AND Firstname ='" & Firstname_txt.Text.Trim & "';"
                con.Open()
                cmd = New SqlCommand(str10, con)
                Dim dr8 As SqlDataReader
                dr8 = cmd.ExecuteReader
                While dr8.Read
                    Dayshift_txt.Text = dr8(0)
                End While
                con.Close()

Edited 3 Years Ago by chdboy

Hi,

Try using Month(AttendanceDate)

"Select COUNT(DayShift) FROM Attendance WHERE AttendanceStatus = 6 AND " _
& " Month(AttendanceDate) = " & Month(DateTimePicker1.Text) & " AND Firstname ='" _
& Firstname_txt.Text.Trim & "';"

Regards
Veena

This question has already been answered. Start a new discussion instead.