Real Software Forums
http://forums.realsoftware.com/

StyleGrid
http://forums.realsoftware.com/viewtopic.php?f=20&t=39722
Page 1 of 1

Author:  JohnWheeler [ Wed Jul 06, 2011 5:24 pm ]
Post subject:  StyleGrid

Hi,

I am trying to save the data from a Stylegrid to an sql database.

Not entirely sure that I am doing it correct, the code appears to collect the data correctly from the cells but I keep getting a message from the CEditDirect class, that the table "users" does not contain a column "myname" or the column "myname" is not unique.

Does anyone have any experience using the Stylgrid with the edit class.

Here is my code to save the data.

dim a,ColumnCount as Integer
dim db1 as new REALSQLDatabase
dim rec As DatabaseRecord


dim f As FolderItem = SpecialFolder.Desktop.Child("customer.sqlite")

If f<>Nil then //if the user didn't cancel..
If f.exists then //if it is a valid file...

db1.databaseFile = f
else
MsgBox "Database File not found!"
end if
end if

if not db1.databaseFile.exists then
msgbox "Can not find database"
end if

if not db1.Connect then
msgbox "Can not Connect to database"
end if



ColumnCount = StyleGrid3.Cols


for a = 1 to ColumnCount
// create a new record and fill in the data from the row
rec = new databaseRecord

rec.column( "myname" )= StyleGrid3.CellText(a,1)
rec.column( "address1" )= StyleGrid3.CellText(a,2)
rec.column( "address2" )= StyleGrid3.CellText(a,3)

// insert the record
db1.insertRecord "users",rec

if db1.error then// check for errors
msgBox db1.errorMessage
return
end
next
// commit changes to database
db1.commit


Regards
John

Author:  timhare [ Wed Jul 06, 2011 5:43 pm ]
Post subject:  Re: StyleGrid

Not sure that StyleGrid or CEditDirect has anything to do with it. You're using vanilla database code here, so my best guess is that the database file and/or table isn't what you think it is. The error message is coming directly from the database engine, so it would appear that in this particular file, the users table doesn't actually contain a column named "myname".

Author:  JohnWheeler [ Wed Jul 06, 2011 6:01 pm ]
Post subject:  Re: StyleGrid

Thankyou Tim,

I made that database using sqlite manager and it did indeed contain a column "myname"

So, I deleted it and done it once more and it saves fine. Odd!

Regards

John

Author:  JohnWheeler [ Fri Jul 08, 2011 6:51 am ]
Post subject:  Re: StyleGrid

Hi,

Thought I would carry on using this post as its all related, I am now filling the Stylegrid from a database.
dim db1 as new REALSQLDatabase
dim RecordSet1 as RecordSet
Dim nRow as New StyleGridRow(StyleGrid1)

dim f As FolderItem = SpecialFolder.Desktop.Child("cust.sqlite")

If f<>Nil then //if the user didn't cancel..
If f.exists then //if it is a valid file...

db1.databaseFile = f
else
MsgBox "Database File not found!"
end if
end if

if not db1.databaseFile.exists then
msgbox "Can not find database"
end if

if not db1.Connect then
msgbox "Can not Connect to database"
end if

RecordSet1 = db1.SQLSelect("select * from users ")

StyleGrid1.LockDrawing = True
While Not RecordSet1.EOF

nRow.WritableCell(1).Text = RecordSet1.IdxField(1).StringValue
nRow.WritableCell(2).Text = RecordSet1.IdxField(2).StringValue
nRow.WritableCell(3).Text = RecordSet1.IdxField(3).StringValue

StyleGrid1.AppendRow nRow

nRow.Recreate
RecordSet1.MoveNext

Wend
RecordSet1.Close
StyleGrid1.LockDrawing = False


Which is fine for filling new rows, but I want to create rows that have controls, mainly popup type
and this code just appends the rows to those I create in code. I need some help in populating the created rows.

I have tried InsertRow but this just blanks out the created rows.

Regards
John

Author:  swort [ Sat Jul 09, 2011 9:30 am ]
Post subject:  Re: StyleGrid

should this:
ColumnCount = StyleGrid3.Cols ' change to the num of rows?


for a = 1 to ColumnCount


be somtething like:
RowCount = StyleGrid3.Rows ' Or .RowCount?

for a = 1 to RowCount

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/