IF it does in fact return an integer then the above code could be:
Var row As New DatabaseRow
Var pid As Integer
row.Column("Name").StringValue = "Penguins"
row.Column("Coach").StringValue = "Bob Roberts"
row.Column("City").StringValue = "Boston"
Try
pid = myDB.AddRow("Team", row)
Catch error As DatabaseException
MessageBox("DB Error: " + error.Message)
End Try
my problem is I am not a software engineer. i dont think in computer language.
i am trying all kinds of syntax and keep getting an error during compile: there is more than one method with this name but this does not match any of the available signatures
most recent try:
io=isdb.AddRow(“demographics”, row,“pid” = “”)
i know its gotta be my syntax but…
What I am trying to do is right from the Xojo documentation. It appears to be a second addrow method that returns the ID from the new table when used …
Don’t get any compile errors at all with the example from Xojo docs with:
Var db As New PostgreSQLDatabase
db.Host = "192.168.1.172"
db.Port = 5432
db.DatabaseName = "BaseballLeague"
db.UserName = "broberts"
db.Password = "streborb"
Var row As New DatabaseRow
' ID will be updated automatically
row.Column("Name") = "Penguins"
row.Column("Coach") = "Bob Roberts"
row.Column("City") = "Boston"
Var ID As Integer
Try
ID = db.AddRow("Team", row, "id")
Catch error As DatabaseException
MessageBox("DB Error: " + error.Message)
End Try
Well…just crashes when it wants to try to a PSQL server where I don’t have exposed for obvious reasons (o;
Besides… you have shown us only a snippet of your code…
Do you try to add this maybe to an older API 1 project where the column returning didn’t exist?
I started this project about 3 weeks ago with an all new download of Xojo, on windows.
This is an addrow that WAS working within a method. I just need to acquire the row id (auto-increment) that MySQL assigns and to set the appropriate textfield.text. (Basically, it’s a patient account number, and I am adding a new patient)
Trying to change the addrow sql statement with this third parameter “id” isn’t working. In your example you use “id” at the end of the sqlselect statement- is that the variable you created or the name of your database-tables -id- column?
The column name I used is just an example….whatever you use as your primary key name, put it there….I always use id on my psql servers for every table. But then again I never used Xojo to connect to a DB server (o;
But you say that you still get compiler errors…
My example did compile without errors and no existent database….
Var NewArtistID As Integer
Var row As New DatabaseRow
Var DbID As Integer
If tfArtistName.Text.Length > 0 Then //Checks to make sure the artist name is at least 1 character long
NewArtistID = DataAccess.getNextId("artist", "ArtistId")
row.Column("ArtistId") = NewArtistID
row.Column("Name") = tfArtistName.Text
Try
DbID = app.db.AddRow("artist", row)
InitListBox()
SaveControlsToggle(False)
Catch error As DatabaseException
MessageBox("Error: " + error.Message)
End Try
Else //If the artist name is of zero length then:
MessageBox("You must supply an artist name before saving.")
End If
MessageBox("The id is: " + str(DbID))
I appreciate immensely everyone attempting to help me out!!! Thank you everyone. You guys are seriously awesome and helpful🤛
Apparently this is a situation I should address with Xojo…
I can get it to compile but it throws a database exception while running. In the mean time I will figure a work-around.
Well if compiling throws no error anymore then I would check the how the database/table is setup.
Can you show us how your table is defined and what DB you’re using?
For example with PostgreSQL you have no primary key that gets incremented automatically. You have to create a sequence first and assign that to the column you want to be incremented.
But how about just querying your database and return some rows? Is that working? Or does it throws the same dbexception?
PostgreSQL has had the Serial data type for a wee bit which is their “autoincrement” data type and comes in three flavors:
smallserial
serial
bigserial
the database is mysql - i am inserting and updating rows and the primaryKey autoincrement field is working perfectly. It is definitly this “new” function that returns the primary key ID# that is throwing it. I did try about every combo I could come up with, twice, all to no avail. I don’t but maybe think this primary key is not the “first” field in the table (i had changed the pK field part way along and deleted the original pK field). Not sure i can move it though and i can’t imagine that would matter since the function asks for the name of the pK field.
I did figure a workaround that will work for me as this dB is going to be lightly used. Thank you for your thought, everyone. I am pretty convinced there may be a bug since this is a pretty new function
Just create a VM in your machine, make it in bridge mode so it gets an IP like another physical computer, install all DBs you want, connect to your local isolated and disposable DBs as you wish.