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()

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

Thanks Veena It worked :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.