Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL Grid Problem?

Status
Not open for further replies.

warik

Programmer
Jun 28, 2002
169
ID
Hi, I make a MyODBC (MySQL) to write down table to grid with this code:

NumRows = SQLEXEC(myConnection, "select Mailbox from coba", 'MyCursor')
ThisForm.Grid1.RecordSource= "mycursor"


But If I modified that table value (delete or Add record), I have to refresh the grid value. To refresh the value I can not use thisform.grid1.refresh, because it have to read from MySQL server to get newest data. Well, so I have to recall the code above again to show at the same Grid.

The problem is, when I use above code for show grid for the second time, the grid event will be reset so the format for column width, header text, etc. Also the event at clik procedure or dblclick procedure will be gone.

What should I do to solve this problem?
Thank you in advance.
 
Warik,

The usual solution to this problem is to maintain two cursors. Use one of them as the recordsource for the grid; use the other to receive the data from the server. When you need to refresh the data, zap the first cursor and append to it all the records from the second cursor.

That way, the grid will never lose its recordsource, and the problems you mentioned won't arise.

If you would like to see some sample code for this, look at my article "Controlling grid data dynamically", at:

Mike




Mike Lewis
Edinburgh, Scotland
 
Yes Mike, you right with make a temporary cursor and copy all data to it will be keep the grid setting.

Thank you very much, your help and your link for sample is really great and it solved my problem.
 
Hi
You can also define a remote view based on MySQL table and execute Requery() when you want to refresh data. You will need a database container for this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top