setting variable value from a listbox

I have been able to find all sortd of documentation about populating a list box from a database but cant find any examples of populating a database from a listbox. at the moment I’m just trying to get one row from the listbox and set a variable I can us to add a record to a database. the following code doesn’t seem to work:
dim urlstr as string = URLList.rowid.urlfield.text

I get the error message no member named rowid. can anyone tell me what I’m doing wrong or point me to some documentation that explains how to do this?

Thanks, in advance for any help you can provide.

for i=0 to listbox1.listcount-1
  data=listbox1.cell(i,0) // string value of listbox at row "I", column 0
 .... do something with it
next i

did you read Database.InsertRecord from here ?
for example…

BTW: once you access to one of the DataBase entries (in developer.xojo.com), many data base related entries appears in the left column. Usually very helpful.

I have the following code assigned to a button:
URLList.AddRow(URLField.Text)

	dim urlstr as string 
	dim i as Integer
	for i=0  to URLList.listcount-1
			  urlstr=URLList.cell(i,0) // string value of listbox at row "I", column 0
			
	next 
	updatedb("urldb.sqlite",urlstr)

This code does not generate any errors. I am then trying to invoke a method (updateddb) and pas two parameters to the method(dbname and urlstr) I set dbname to urldb.sqlite before calling updatedb. the updatedb method follows:

	Dim dbFile As FolderItem = SpecialFolder.Desktop.Child(dbname)
	Dim db As New SQLiteDatabase
	Dim d As Xojo.Core.Date = Xojo.Core.Date.Now
	db.DatabaseFile = dbFile
	
	If db.Connect Then
			  //proceed with database operations here.
			row.Column("url") = urlstr
			row.Column("comments") = "comment"
			row.Column("changedate") = d
			App.db.InsertRecord("urldata", row)
			MsgBox("open successful")
	Else
			  MsgBox("The database couldn't be opened. Error: " + db.ErrorMessage)
			
	End If

I get an error on rows 8,9,10 stating the items don’t exist. the app.db.insertrecord statement gives me an error telling me the app doesn’t have member named “db” even though I defined it at the beginning of the method. Can somone tell me what I am doing wrong here? Better yet if you could point me to a good example of passing parmeters to a method It would be greatly appreciated.

Thanks, in advance for any help you can provide.

for i=0 to URLList.listcount-1
urlstr=URLList.cell(i,0) // string value of listbox at row "I", column 0

next 
updatedb("urldb.sqlite",urlstr)

this section returns the LAST value in the listbox in “urlStr”. you are either wasting time by looping thru it, or you are not doing what you think you are doing… And of course WE don’t know what “updatedb” is supposed to be doing.

NO, you do NOT have app.db (unless you defined it elsewhere), what you defined in the code above is just plain “DB”
where is “ROW” defined?, just because you connected to the database, nowhere did you perform any action that related to a TABLE, or the structure of a table… the code doesn’t know what “ROW” is, and therefore does not know what “URL”,“COMMENTS” or “URLDATA” is.

I suggest you go back to the documents, and examples and read more about databases, and then come back after you have re-written the above code

I suspect you are missing a line like

Dim row As New DatabaseRecord

And, as Dave wrote, App.db is not the same as the locally defined variable db.

I an using the code from the example in how to insert a record see below:
Dim row As New DatabaseRecord
// ID will be updated automatically
row.Column(“Name”) = “Penguins”
row.Column(“Coach”) = “Bob Roberts”
row.Column(“City”) = “Boston”

App.DB.InsertRecord(“Team”, row)

If App.DB.Error Then
MsgBox("DB Error: " + App.DB.ErrorMessage)
End If

how is this different that what I have coded? I don’t see app defined anywhere. Also I WANT the last value in the list to use it in adding a record to the database. Sorry if I seem to be floundering here. Thanks for your responses.

So if you want the LAST value, then just GET the last value… no need to read all of them

urlstr=URLList.cell(listcount-1,0) // string value of listbox at the last row, column 0
updatedb("urldb.sqlite",urlstr)

Thank you for that last tip. everything is now working as I want/expect it to.