Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Dec 07, 2019 8:34 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: StyleGrid
PostPosted: Wed Jul 06, 2011 5:24 pm 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
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


Top
 Profile  
Reply with quote  
 Post subject: Re: StyleGrid
PostPosted: Wed Jul 06, 2011 5:43 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
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".


Top
 Profile  
Reply with quote  
 Post subject: Re: StyleGrid
PostPosted: Wed Jul 06, 2011 6:01 pm 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
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


Top
 Profile  
Reply with quote  
 Post subject: Re: StyleGrid
PostPosted: Fri Jul 08, 2011 6:51 am 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
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


Top
 Profile  
Reply with quote  
 Post subject: Re: StyleGrid
PostPosted: Sat Jul 09, 2011 9:30 am 
Offline

Joined: Mon May 31, 2010 5:35 am
Posts: 2412
Location: Netherlands
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

_________________
SWORT™
- Windows Vista, Windows XP, Windows 7, Linux Mint 11 and Mac OSX Lion
- REAL Studio Enterprise(latest) and WEB Edition(latest)
- Plugins (MBS Complete, ToringoLib, Einhugur, VanHoek + Some open source plugins)
For Dutch User Groups ask me to enter!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group