I'm trying to retrieve the last ID, in a table, using SQL query and then append the result together with a TextBox value (which is a String):
Dim searchforID = New OleDbCommand("select ID from [table1] where ID = (select max(id) from [table1])", con)
Dim variable1 = searchforID + TextBox1.Text
But it throws this error:
Compiler Error Message: BC30452: Operator '+' is not defined for types 'System.Data.OleDb.OleDbCommand' and 'String'.
Trying to fix it
-- So i tried to convert the returned record ID like this:Dim variable1 = Convert.ToString(searchforID) + TextBox1.Text
There is no error now but unfortunately the result returned is "System.Data.OleDb.OleDb" + the textbox value, as this example:
System.Data.OleDb.OleDbtest
-- I too thought to convert the returned record ID to integer throws an error:
Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Data.OleDb.OleDbCommand' to type 'System.IConvertible'.
So why does retrieving the last record ID fail? Might my SQL query be false?
Thank you.
So straight forward solution for problem if someone may find it useful:
Dim searchforID = New OleDbCommand("select MAX(ID) from [table1]", con)
Dim variable1 = searchforID.ExecuteScalar() & TextBox1.Text
Also the answers and comments below have useful information.