0

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
3
Contributors
2
Replies
17
Views
2 Years
Discussion Span
Last Post by PerplexedB
0

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
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.