2,892 questions
Change:
sql1 = "SELECT TOP (100) PERCENT FullName, FunctionCode, DateTime FROM dbo.timeclockpunches WHERE (DateTime BETWEEN " & id & " AND " & id2 & ") AND (FullName =" & id3 & ")"
to:
sql1 = "SELECT TOP (100) PERCENT FullName, FunctionCode, DateTime FROM dbo.timeclockpunches WHERE (DateTime BETWEEN @start AND @end) AND (FullName = @name)"
Then after:
Dim comm As SqlClient.SqlCommand = New SqlClient.SqlCommand(sql1, conn)
Add:
comm.Parameters.Add("@start", SqlDbType.Date).Value = Date1.Value
comm.Parameters.Add("@end", SqlDbType.Date).Value = Date2.Value
comm.Parameters.Add("@name", SqlDbType.NVarChar, 40).Value = namecbx.SelectedValue
Building an SQL string by inlining values as you tried to do is difficult to get right. It is a lot easier to use a parameterised commands. That is, you use these things starting with @ and then you defined with SqlCommand.Parameters.Add.