[Gambas-user] Database example
charlesg
charles at ...1784...
Fri Jun 19 11:03:06 CEST 2009
Hi
Thank you Ron for that. A bit more messing around and I think I now
understand it.
Following on from richard terry's suggestion for simple examples, here it is
as simple as I can get it. There is nothing new here: it all comes from the
database example. Any corrections to the annotations welcome!
You just need a gridview, a button called btnRun and a preferably large
database with lots of columns so that you can scroll around with ease
'========================================================
' Gambas class file
PUBLIC $hConnLocl AS NEW Connection
PUBLIC $resData AS Result
'--------------------------------------------------------
PUBLIC SUB Form_Open()
DIM sql AS String
'open the database
WITH $hConnLocl
.type = "mysql"
.host = "localhost"
.Name = "stock"
.login = "charles"
.password="dog"
END WITH
$hConnLocl.Open()
'create a result
sql = "SELECT * FROM grnLine"
$resData = $hConnLocl.Exec(sql)
END
'---------------------------------------------------------
PUBLIC SUB btnRun_Click()
DIM hForm AS FRequest
DIM hField AS ResultField
DIM iInd AS Integer
GridView1.Rows.count = 0
'set the required number of columns
GridView1.Columns.count = $resData.Fields.Count
'define the column headers and width
FOR EACH hField IN $resData.Fields
WITH hField
GridView1.Columns[iInd].text = .Name
GridView1.Columns[iInd].width = 60
END WITH
INC iInd
NEXT
'create the empty rows. Each empty and visible cell created calls
GridView1_data
GridView1.Rows.Count = $resData.Count
END
'---------------------------------------------------------
PUBLIC SUB GridView1_Data(Row AS Integer, Column AS Integer)
'move to the required result row
$resData.MoveTo(row)
'set the data for the cell in the GridView from the column in the selected
row of the result
GridView1.Data.text = Str($resData[GridView1.Columns[column].text])
'lets you see how _data is being called as you scroll around the GridView
PRINT row & ":" & column & ":" &
Str($resData[GridView1.Columns[column].text])
END
'----------------------------------------------------------
I also created a second small form. As you move the second form around on
top of the gridview, the print command still shows the _Data frantically
working in the background. Clever things these computers!
rgds
--
View this message in context: http://www.nabble.com/Database-example-tp24021356p24107894.html
Sent from the gambas-user mailing list archive at Nabble.com.
More information about the User
mailing list