Variable in db.AddRow!

Hello everyone,
How to insert a string variable in a db.AddRow command?
Here’s my code, of course I get a databaseException → near"(":syntax error
datedujour is a string

Var PersonRecord As New DatabaseRow

PersonRecord.Column("Prenom").StringValue = Prenom.value
PersonRecord.Column("PhotoVideo").StringValue = Format(DateTime.Now.Hour,"00") + Format(DateTime.Now.Minute,"00") + Format(DateTime.Now.Second,"00") + s.LeftBytes(5) + uFile.Name
PersonRecord.Column("Identifiant").StringValue = "0"

Try
  
  db.AddRow(datedujour, PersonRecord)
  
Catch e As DatabaseException
  
  MessageBox(e.Message)
  
End Try

Thank you for your help.

That would indicate that datedujour contains invalid data.

1 Like

Indeed, after checking, the variable was empty!
However, it is declared as public and defined in another event. Is it possible to retrieve it from anywhere in the code?

No.

A variable life is short. It exists only where you define it (even ony in an if Then Block !). And I do not talked about its value.

Use a Window Property / Module Property or App Property instead.


But that’s what I did!

please take a look at the database examples provided with xojo …
they are quite well made, and will prevent you from making horrible database spaguetti …

dbkit in the example/database folder, or eddieelectronics in examples/sample apps folder

once you understand how they work, then try to make your own.
dbkit has been made for this purpose !

1 Like

A common mistake is to have a property defined and then also have a local variable with the same name in the code where you set its value. In that case, the local variable gets set, not the more global property. Make sure you don’t have a Var datedujour as String statement in your code.

1 Like

Problem solved:
I changed the format of Firstname column back to String
And I deleted .Stringvalue from this line → productName = data.Column(“Firstname”)
It was the .Stringvalue that was causing the problem!