Hello everyone please your help with the correct syntax of this code i´ve just build it but the visual studio has closed the session and i lost all my work

the code as you can see search between two dates that part its ok, and then search in another field of my database to validate that the information that read is the correct
how can i join up those two code
one search between two dates and the other search a value from my drop down list

Protected Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        Dim T1 = New DateTime(Now.Year, Now.Month, Now.Day, 6, 0, 0)
        Dim T2 = New DateTime(Now.Year, Now.Month, Now.Day, 14, 0, 0)
        Dim T3 = New DateTime(Now.Year, Now.Month, Now.Day, 22, 0, 0)


        Dim str As String
        Dim con As OleDbConnection
        Dim sql As String
        str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\MXDTBTZ3XC1\Users\MXDTBTZ3XC1\Desktop\CHECKLIST.accdb"
        con = New OleDbConnection(str)
        sql = "select * from EQUIPOS where NO_VEHICULO = '" & DropDownList2.SelectedValue.ToString & "'and DIA Between #" & TextBox2.Text & "# and #" & T1 & "#"""

        Dim cmd As OleDbCommand
        Dim r As OleDbDataReader
        con.Open()
        cmd = New OleDbCommand(sql, con)
        r = cmd.ExecuteReader()
        If r.Read Then
            TextBox4.Text = r("PORCENTAJE_BATERIA")
        End If
        con.Close()

    End Sub

Remove two duoble quotation mark at the end of the SQL statement which may the cause to close the session.

Use parameterised query to protect your database from unauthorised SQL injections and also it can help you to use spacial characters in your query.

Dim cmd As New OleDbCommand
sql = "select * from EQUIPOS where NO_VEHICULO = ? and DIA Between ? and ?"
cmd.Parameters.AddWithValue("@vehi", DropDownList2.SelectedValue.ToString)
cmd.Parameters.AddWithValue("@dt1", CDate(TextBox2.Text))
cmd.Parameters.AddWithValue("@dt2", T1)
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.