Hi guys,
I wanted to extract a field from a table by date and two other criterias,but it's giving me an exception.
The field that is a long integer data type and i used integer in the code.And the date is also available in the database.
Am i missing something?

resultdate = DateTimePicker1.Text
qry = "SELECT * FROM [per_diem_accomodation] WHERE [project number]='" & projcode & "' AND [employee number]='" & empcode & "' AND " & _
            "[current month]='" & resultdate & "'"
            Dim dr1 As OleDb.OleDbDataReader = GetData(qry)
            If dr1.HasRows = True Then
                Do While dr1.Read
                    pdanumber = (CInt(dr1.Item("pda number")))
                Loop
            End If

Try removing the single quotes from the numeric fields as in

qry = "SELECT * FROM [per_diem_accomodation] " &
      " WHERE [project number]  = " & projcode & 
      "   AND [employee number] = " & empcode  &
      "   AND [current month]   = '" & resultdate & "'"

Also, you didn't say what the backend database was. If it is Access then you should delimit the date with # instead of single quotes. In any case you should be using parameterized queries.

try this :

"SELECT * FROM [per_diem_accomodation] WHERE 
[project number]='" + projcode + "' 
AND 
[employee number]='" + empcode + "' 
AND 
[current month]='" + resultdate + "'"

Thanks Jim 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.