locked
problem with function - error with sql statement RRS feed

  • Question

  • User-1892634376 posted

    So I have a function that is looking for the last value in the primary key column (1001,1002, etc).  The function has the normal OleDbConnection and OleDbAdapter variables but the sql line that I'm trying to set as a string to be passed to Access keeps coming back incorrect.


    Public Function FindMax(ByVal tableName As String, ByVal columnName As String, ByVal Path As String) As TPsStaffSet

            ' Sets up the containers amd the data base connection

            Dim DS As TPsStaffSet

            Dim sqlConn As OleDbConnection

            Dim sqlDA As OleDbDataAdapter

            Dim sql As String



            ' Sets up the database connection and looks for the address

            sqlConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & Path & "")

            sql = "SELECT MAX(" & columnName & ") FROM " & tableName  --the error starts here

            ' Fills the container with the found address

            sqlDA = New OleDbDataAdapter(sql, sqlConn)

            ' sets up the new object for the found address

            DS = New TPsStaffSet

            ' fills up the new object with the address

            sqlDA.Fill(DS.CONTRACT)

            Return DS

        End Function


    Any suggestion??

    Saturday, October 16, 2010 11:53 PM

Answers

All replies