Advertisement
Guest User

Create table sqlite, recuered gridview1 (нарисовать)

a guest
Jul 28th, 2017
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GAMBAS 2.16 KB | None | 0 0
  1. ' Gambas class file
  2.  
  3. ' Gambas class file
  4. Private $hConn As New Connection
  5. Private $res As Result
  6. '-------------------------------------------------
  7. Public Sub Form_Open()
  8. Dim iCount As Integer
  9. Dim hTable As Table
  10. Dim rTest As Result
  11. Dim sql As String
  12.  
  13. 'define the gridview layout
  14. GridView1.header = GridView.Horizontal
  15. GridView1.grid = True
  16. GridView1.Rows.count = 0
  17. GridView1.Columns.count = 2
  18. GridView1.Columns[0].text = "ID"
  19. GridView1.Columns[1].text = "Value"
  20. GridView1.Columns[0].width = 55
  21. GridView1.Columns[1].width = 55
  22.  
  23.  
  24. With $hConn
  25.     .Type = "sqlite"
  26.     .host = User.home
  27.     .name = ""
  28. End With
  29.  
  30. 'delete an existing test.sqlite
  31. If Exist(User.home & "/test.sqlite") Then
  32.     Kill User.home & "/test.sqlite"
  33.     Print "Kill ok " & User.Home
  34. Endif
  35.  
  36. 'create test.sqlite
  37. $hConn.Open
  38.     $hConn.Databases.Add("test.sqlite")
  39. $hconn.Close
  40.  
  41. 'define the table sampleTable
  42. $hconn.name = "test.sqlite"
  43. $hConn.Open
  44.     hTable = $hConn.Tables.Add("sampleTable")
  45.     hTable.Fields.Add("s_seq", db.Integer)
  46.     hTable.Fields.Add("s_rndm", db.Integer)
  47.     hTable.PrimaryKey = ["s_seq"]
  48.     hTable.Update
  49.  
  50. 'fill the table with generated data
  51. $hconn.Begin
  52.     rTest = $hConn.Create("sampleTable")
  53.     For iCount = 1 To 10000
  54.         rTest!s_seq = iCount
  55.         rTest!s_rndm = Int(Rnd(0, 100))
  56.         rTest.Update
  57.     Next
  58. $hConn.Commit
  59.  
  60. 'read the database
  61. sql = "select s_seq as ID, s_rndm as Value from sampleTable"
  62. $res = $hconn.Exec(sql)
  63.  
  64. 'Catch dose not worked, why!?  
  65. 'Catch
  66. '$hConn.Rollback
  67. 'Message.Error(DConv(Error.Text))
  68.  
  69. End
  70. '-------------------------------------------------
  71. Public Sub Form_Activate()
  72. 'change the rowcount of the gridview from 0 to the number of records.
  73. 'This triggers the data handling event
  74.  
  75. GridView1.Rows.Count = $res.Count
  76. End
  77. '-------------------------------------------------
  78. Public Sub GridView1_Data(Row As Integer, Column As Integer)
  79.     $res.moveTo(row)
  80.     GridView1.Data.text = Str($res[GridView1.Columns[column].text])
  81. End
  82. '-------------------------------------------------
  83. Public Sub Form_Close()
  84.     $hconn.Close
  85. End
  86. '-------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement