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

Recommended Answers

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

Jump to Post

All 2 Replies

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 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.