[Gambas-user] TableView Data from database

Tobias Boege taboege at ...626...
Sat Sep 29 09:13:53 CEST 2012


On Thu, 27 Sep 2012, rocko wrote:
> I'm using a Table view to view data from an SQLite database.
> I would use a dataview but I only need to display some database fields
> not all of them.
> 
> This is the code I have so far:
> Public Sub Form_Open()
> 
> Dim sResult As Result
> Dim id As Integer
> 
>   TableView1.Columns.Count = 3
>   TableView1.Rows.Count = 10
> 
>   TableView1.Columns[0].Title = ("ID")
>   TableView1.Columns[0].Width = (TableView1.Width / 10) * 2
>   TableView1.Columns[1].Title = ("Location")
>   TableView1.Columns[1].Width = (TableView1.Width / 10) * 4.5
>   TableView1.Columns[2].Title = ("Days Left")
>   TableView1.Columns[2].Width = (TableView1.Width / 10) * 2
> 
>   sResult = DB.Edit("inventory", id = &1, ID)
>   sResult!id = ID
>   sResult!location = TableView1.Columns[1].
>   sResult.Update
> 
> I obviously get an error at runtime on the second to last line as I'm
> not sure how to put data from the database into the table column.
> 
> I believe I asked this question before using a dataview on how to
> display only some data from the database as using a dataview would be
> easier but I never got a response so I'm trying a table view as it has
> more options--at least I think so.
> 
> Any help would be appreciated.

Your code does not match your goal at all - *if I* got you right! - and the
other replies go all in that wrong direction.
You said: "I want to *display* only certain fields of a table" but your
trial code says: "I want to *update the table* with data from a TableView".

You can indeed use the more convenient DataView control but you have to read
the docs[0] first. This should be enough:

DataView.Columns = ["id", "location", "daysleft"]
' ... or whatever the names of your fields are.

Does this fit your needs?

Regards,
Tobi

[0] http://gambasdoc.org/help/comp/gb.db.form/dataview/columns?v3




More information about the User mailing list