question

Mischa Spelt avatar image
0 Likes"
Mischa Spelt asked Mischa Spelt answered

Parameters in prepared statement

Hi,

How can I use parameters in an SQL Server prepared statement?

I tried

Database.Connection conn = Database.Connection("BOPSO");
Database.PreparedStatement stmt = conn.prepareStatement("SELECT * FROM MyTable WHERE Id = @Id");
stmt.bindParam("Id", 1, Database.DataType.Int);

but that gives me "FlexScript exception: Bind variable/parameter 'Id' not found". When I replace @Id by :Id I get "FlexScript exception: API client not set" instead.

FlexSim 18.1.0
databasesql server
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Mischa Spelt avatar image
0 Likes"
Mischa Spelt answered

I figured it out myself shortly after posting this. The message

FlexScript exception: API client not set

means that the connection to the database is closed, I forgot to conn.connect();

The parameters should be specified with a colon, so not @Id but :Id

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.