hi guys,
I wanted to get a result of a certain field by passing a month and year parameter to access database,the day parameter isn't important.So i used this query and it raised an exception.The record exists but it says there's no data for that column.
Any help would be appreciated.

qry = "SELECT * FROM [fuel_allowance] WHERE [project number]='" & projcode & "' AND [employee number]='" & empcode & "'" & _
                "AND MONTH([current month])=" & currentdate.Month & " AND YEAR([current month])=" & currentdate.Year & ""

        Dim dr As OleDb.OleDbDataReader = GetData(qry)
        If dr.HasRows = True Then
            TextBox32.Text = dr.Item("fuel/litre")
        Else
            MsgBox("Fuel allowance not defined for the current month of " & MonthName(currentdate.Month, False), MsgBoxStyle.Information, "Project Payroll")
            Exit Sub
        End If

when you use the getdata methode it collect the values in your query, your "fuel/litre" is no longer there. instead use this code to get your item

        Dim qry As OleDb.OleDbCommand
        Dim dr As OleDb.OleDbDataReader
        qry = New OleDbCommand("SELECT * FROM [fuel_allowance] WHERE [project number]='" & projcode & "' AND [employee number]='" & empcode & "'" & _
            "AND MONTH([current month])=" & currentdate.Month & " AND YEAR([current month])=" & currentdate.Year & "", YourConnection)
        dr = qry.ExecuteReader
        If dr.Read Then
            TextBox32.Text = dr("fuel/litre")
        End If

Does this Dim dr As OleDb.OleDbDataReader = GetData(qry) compile at all?

I don't think GetData does what you think it does. You need to use an oledbCommand, connect to your database, link the connection to the command and submit your query to the command which may eventually produce a datareader.

Once you have the dr, you must read it before you can retrieve the info.

My 2 Eurocent.

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.