Reference SQL table name with variable

mangojack

Expert
Licensed User
Longtime User
I cannot find any positive yes or no on this.

Is it possible to to reference an SQL table by way of variable.

ie:
Dim Tname as string : "MyReports"

SQL1.ExecNonQuery ("INSERT INTO "' & Tname & "' VALUES (NULL, "somedata)")

Cheers mj
 

klaus

Expert
Licensed User
Longtime User
Sure you can !
But you must change the query from
B4X:
SQL1.ExecNonQuery ("INSERT INTO "' & Tname & "' VALUES (NULL, "somedata)")
to:
B4X:
SQL1.ExecNonQuery ("INSERT INTO " & Tname & " VALUES (NULL, somedata)")
or :
B4X:
SQL1.ExecNonQuery ("INSERT INTO " & Tname & " VALUES (NULL, '" & somedata & "')
No single quotes and in your example the first single quote should have been before the double quote.
The double quote before somedata is wrong too.
The example in the User's Guide uses a variable for the table name.

Best regards.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Thanks Again Klaus.. I was aware of the somedata syntax , just messy in my example.

Cheers mj
 
Upvote 0
Top