Hi all.
I’m pulling my hair out here (and I don’t have much left). Running the following code in a LostFocus event and it will only perform the try/Catch in the if/else where rowsFound <> Nil. If I swap the = and <> signs around, it just performs as if the rowsFound are not nil, even when there are no rows. But, if I remove the if/else all together, it throws a NilObjectException (as it should, there are no rows).
Anybody???
If Me.Value <> “” Then
Var customerID As String = App.CustID
Var Content As String = Me.Value
Var rowsFound As RowSet
Try
rowsFound = App.db.SelectSQL(“SELECT * FROM customers”)
Catch error As DatabaseException
MessageBox(“Database error.” +EndOfLine+EndOfLine+ “Please contact support, quoting error number PP1LF28.”)
End Try
If rowsFound <> Nil Then
Try
Var ps As SQLitePreparedStatement
ps = SQLitePreparedStatement(App.db.Prepare("UPDATE customers SET content = ?, mod_date = ? WHERE customerID = ?;"))
ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
ps.BindType(1, SQLitePreparedStatement.SQLITE_TEXT)
ps.BindType(2, SQLitePreparedStatement.SQLITE_TEXT)
ps.ExecuteSQL(Content, Today, customerID)
Catch error As DatabaseException
MessageBox("Error writing to the database" +EndOfLine+ "Couldn't write " +ppContent+ " as expected")
End Try
Elseif rowsFound = Nil Then
Try
Var ps As SQLitePreparedStatement
ps = SQLitePreparedStatement(App.db.Prepare("INSERT INTO customers (customername, customer, content, mod_date) VALUES (?, ?, ?, ?)"))
ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
ps.BindType(1, SQLitePreparedStatement.SQLITE_TEXT)
ps.BindType(2, SQLitePreparedStatement.SQLITE_TEXT)
ps.BindType(3, SQLitePreparedStatement.SQLITE_TEXT)
ps.ExecuteSQL(customerVal, customerID, Content, Stage,)
Catch error As DatabaseException
MessageBox("Can't update database." +EndOfLine+EndOfLine+ "Please contact support, quoting error number PP1LF54.")
End Try
End If
End If