?
Solved

Extremely Urgent:  Can't get databound grid to update data

Posted on 2006-04-03
12
Medium Priority
?
281 Views
Last Modified: 2013-12-25
I know this is simple but can't ind the answer anywhere.

bound Datagrid (ADO)  using for editing a table ... if the user modifiies the data in a cell and then closes the form the cell does not get updated in the table.

In fact the record is not updated untill they change to recordselector to a new row no matter what i do!

Help....need to fix this bug to deliver!!!!!

0
Comment
Question by:mnichols1202
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 16367415
try
if you are connected to a adodc data control refresh the data control by
adodc1.refresh then
datagrid1.rebind
datagrid1.refresh


0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 16367426
place this code on the after column update of the grid

Private sub Datagrid1_AfterColumnUpdate()
datagrid1.rebind
datagrid1.refresh
End sub
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 16370812
Are you using .NET or VB?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mnichols1202
ID: 16371860
Sorry Jack, Does not work!

Leon, it's VB 6

This is really weird isn't the Datagrid supposed to handle this stuff automatically? I have got to be doing something worng!

Thanks for the effort so far.

Thinking of switching to the flexgrid control.....any ideas on that?




0
 
LVL 29

Expert Comment

by:leonstryker
ID: 16371918
The first thing to do is to get rid of ADODC or DE. You should be populating any and all of your grids by retrieving an ADO recordset and then binding it to what ever grid you decide to use.

Leon
0
 
LVL 4

Expert Comment

by:pbocanegra
ID: 16374238
In the "Form_Unload" write "recordset.update" where recordset is your data recordset.


0
 

Author Comment

by:mnichols1202
ID: 16377209

Tried binding to an ADO Recordset object - no difference

recordset.update method does nothing.  that was the first thing i tried.

The update method works but ONLY after you change to a different record in the grid
in other words you must MANUALLY cause the row the recod selector is pointing to to change. before anything i've tried to update the dataset works.

I've even tried the update method on evey RowColChange event.  Nothing.

I even change the row programatically ( really crappy solution.... but if it worked......) and that even does not cause the data to save to the table.

This can't work this way...If the datagrid really had this problem it would make it almost unuseable in any kind of edit situation....How could you know if data you changed was commited before sutting down he program, closing a window... anything......


Help Please? I;m getting kind of desperate here







0
 
LVL 29

Expert Comment

by:leonstryker
ID: 16380824
Second, do not use recordset.update method. What you should be doing is creating a SQL string and using that to update your data.
0
 
LVL 4

Expert Comment

by:pbocanegra
ID: 16381046
On the line of the previous commentary:

This is a patch:

In the Form_Unload:

Private Sub Form_Unload(Cancel As Integer)
UpdateDataGridOut
End Sub

Private Sub UpdateDataGridOut
Dim sql as string
Dim x as Integer
 Public cn As New ADODB.Connection

'Suppose that the first column is the key.
sql ="Update table set "
  For x=0 to datagrid1.columns.count -1
      sql = sql & datagrid1.Colums(x).Datafield & ","
  next x
sql = mid(sql,1,len(sql)-1)
sql = sql & ")=("
  For x=0 to datagrid1.columns.count -1
      sql = sql & "'" & datagrid1.Colums(x).value & "',"
  next x
sql = mid(sql,1,len(sql)-1)
sql = sql & ") where " & datagrid1.Columns(0).datafield & "=" & datagrid1.Columns(0).Value

 With cn
     .ConnectionString = "UID=fmb;PWD=fmb;driver={Microsoft ODBC for Oracle};" _
               & "CONNECTSTRING=MERCURIO;"
     .ConnectionTimeout = 20
     .Properties("Prompt") = adPromptNever
     .CursorLocation = adUseServer
     .Open
 End With
cn.execute sql
End Sub
0
 
LVL 4

Accepted Solution

by:
pbocanegra earned 2000 total points
ID: 16381110
PLease try this in Form_Unload

If (rs.EditMode > 0) Then rs.Bookmark = rs.Bookmark
0
 

Author Comment

by:mnichols1202
ID: 16715011
Sorry, Thought I had closed this. My appologies

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question