Issue with db.InsertRecord

Hi

I like xojo. I have the following issue with my application:

I can’t insert new records from my window into my mySQL dBase.

The source code is the following:
Dim rec as new DatabaseRecord // Mit rec bilden wir eine neue Instanz der Klasse DatabaseRecord

Dim db as new Database
db=f_connect

rec.Column(“da_eigene_kundennummer”)=Datenerfassung.edit_eigene_kundennummer.Text
rec.Column(“da_firma_1”)=Datenerfassung.edit_firma_1.Text
rec.Column(“da_firma_2”)=Datenerfassung.edit_firma_2.Text
rec.Column(“da_anrede”)=Datenerfassung.edit_anrede.Text
rec.Column(“da_vorname”)=Datenerfassung.edit_vorname.Text
rec.column(“da_nachname”)=Datenerfassung.edit_nachname.Text
rec.column(“da_strasse”)=Datenerfassung.edit_strasse.Text
rec.column(“da_plz”)=Datenerfassung.edit_plz.Text
rec.column(“da_ort”)=Datenerfassung.edit_ort.Text
rec.column(“da_land”)=Datenerfassung.edit_land.Text
rec.column(“da_zusatz”)=Datenerfassung.edit_zusatz.Text
db.InsertRecord(“datenerfassung”, rec)
db.commit

Thanks for your help.

did you check for db.errorcode or db.errormessage ?

Hi

Yes this two:
https://mdematteo.sharepoint.com/:f:/s/ExterneDokumente/EroTobkktNROoQzXbbp7QcgBSjPrgHtBNl7eilrMxe-v6w?e=OFQBBh

Thanks for your feedback.

on the first picture clic on the NilObjectException link and you get an error message that should be more explicit.

1 Like

Some database are casesensitive in regards to field names. Don’t think that’s your case as all your fields are in lowercase in your code, but they might not be lowercase in your db. Or you are missing a field (primary key for instance). But as @Jean-Yves_Pochez pointed out, clicking on the NilObjectException should show you what object is acutally Nil.

in the screenshot the db is nil so see why =f_connect returns nil
its better to use a own class and set the super to the database class u need.

because the method return an object you not need new here “Dim db as new Database”

1 Like

Ah okay. Many thanks.