I am new to Xojo, just imported one of my two VB programs that need to be updated.
I can see my data on my mysql database server, and it displays in the forms that I have created. However, it does not save the changes that I make in the forms.
In the data app I have selected the database, and the table. In the sql window I have “SELECT * FROM xxxxxx” (xxxxx would be the table name, depending on what form is open at the moment).
Am I missing a control setting, or what needs to be added to have the data control update the field?
I hope not missunderstanding you. but here is an example how you update Mysql data from simple textfield.
Dim rs as RecordSet
Dim Db as mySQLCommunityServer
Db=New mySQLCommunityServer
// Connect to MySQLServer
Db.host=“IPadress”
Db.port=3306
Db.databaseName=“DBname”
Db.userName=“root”
Db.Password=“Password”
If Db.Connect then //If the database connected:
rs = Db.SQLSelect("SELECT * FROM TableName WHERE primaryKey ='" +TxtFieldID.Text + "'")
if(rs.RecordCount <> 0) then
TxtFieldID.Text = rs.IdxField(1).StringValue
rs.Edit
if TxtFieldEpost.text="" then
else
rs.IdxField(2).StringValue=ConvertEncoding(Lowercase(TxtFieldEpost.text), Encodings.ISOLatin1)
end if
if TxtFieldEName.text="" then
else
rs.IdxField(3).StringValue =ConvertEncoding(Lowercase(TxtFieldName.text), Encodings.ISOLatin1)
end if
rs.Update
Db.Commit
else
MsgBox("User Not found")
end if
if (Db.error) then
msgBox("FAILED!!! " + Db.errorMessage)
else
msgBox("SUCCESS!!!")
end if
rs.Close
Use of DataControl is discouraged. It doesn’t really work. At least, not very well. It is much better to use RecordSet directly or use Prepared Statements. It’s a little more work, but a lot more flexible. And you have control over the process, which is a lot more than you can say with DataControl.
Paul is right here (and certainly most if not all the time).
I implemented my own * and when I was no more in a hurry, I took time to make a check in the Language Reference and found DataControl to realize it the way Paul wrote above.
I had in mind a souvenir of a DataControl from FileMaker (I think), so I implemented something like that but without graphics (no time to search or draw them).