Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Datagrid and MS DB updating?? Everything looks fine but not updating??????

Hi there ppl

I have a Datagrid on a form, I've set the datasource during the Form Load Event.  I've done all the do's and don'ts of datagrid.
It worked fine and I moved on to different part of my program.  Now the Datagrid doesn't update the MS DB anymore?????
Help!!!!!

This is the code i'm using:

Private Sub Form_Load()

ChangeWeight
RefreshGridLearners
RefreshGridDeleteLearners
RefreshGridMarks                       '''This is the one that's got the problem

End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Private Sub RefreshGridMarks()

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQLFieldNames As String

Dim i As Integer
Dim x As Integer
Dim length As Integer

bindFieldNames

i = 0
x = 1

Do Until (i = 16)
    If (fieldNames(i) > "") Then
            SQLFieldNames = SQLFieldNames & " Proj" & x & " as [" & projname(i) & "]"
            i = i + 1
            x = x + 1
            If i = 16 Then
            Else
                SQLFieldNames = SQLFieldNames & ","
            End If
    Else
    GoTo EndOfProjects
    End If
Loop

EndOfProjects:

SQLFieldNames = SQLFieldNames & " ProjTotal, Exam, Rapportmark"

conn.Open connectString

Set DataGrid2.DataSource = Nothing
Set rs = Nothing

rs.CursorLocation = adUseClient
rs.Open "SELECT StudentNum, Name, Surname, " & SQLFieldNames & " FROM Data WHERE Subject = '" & sSubject & "' AND Grade = " & iGrade & " AND Class = '" & iClass & "' AND Term = '" & sTerm & "' ORDER BY Surname", conn, adOpenDynamic, adLockBatchOptimistic

rs.Requery

DataGrid2.AllowUpdate = True
Set DataGrid2.DataSource = rs

End Sub


Everything looks fine....

i have a routine         Private Sub DataGrid2_AfterColUpdate(ByVal ColIndex As Integer)

that does calculations in the datagrid, these calculations is displayed correctly in the datagrid but doesnt get updated in the MSDB.

Help!!!!!!!!!!

MM
0
MarvelousMerlin
Asked:
MarvelousMerlin
  • 6
  • 2
2 Solutions
 
DhaestCommented:
Do you get an errormessage ?
Put an errorhandler in it and let us know what error you get !

Private Sub RefreshGridMarks()
on error goto RefreshGridMarksError
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQLFieldNames As String

Dim i As Integer
Dim x As Integer
Dim length As Integer

bindFieldNames

i = 0
x = 1

Do Until (i = 16)
    If (fieldNames(i) > "") Then
            SQLFieldNames = SQLFieldNames & " Proj" & x & " as [" & projname(i) & "]"
            i = i + 1
            x = x + 1
            If i = 16 Then
            Else
                SQLFieldNames = SQLFieldNames & ","
            End If
    Else
    GoTo EndOfProjects
    End If
Loop

EndOfProjects:

SQLFieldNames = SQLFieldNames & " ProjTotal, Exam, Rapportmark"

conn.Open connectString

Set DataGrid2.DataSource = Nothing
Set rs = Nothing

rs.CursorLocation = adUseClient
rs.Open "SELECT StudentNum, Name, Surname, " & SQLFieldNames & " FROM Data WHERE Subject = '" & sSubject & "' AND Grade = " & iGrade & " AND Class = '" & iClass & "' AND Term = '" & sTerm & "' ORDER BY Surname", conn, adOpenDynamic, adLockBatchOptimistic

rs.Requery

DataGrid2.AllowUpdate = True
Set DataGrid2.DataSource = rs
exit sub
RefreshGridMarksError:
 msgbox err.number & " " & err.description  
End Sub
0
 
TimCotteeCommented:
Hi MarvelousMerlin,

Why have an "After" col update event? This will fire after the database has been updated. Logically then it will not be able to update the database itself. Perhaps you should use Before_ColUpdate event instead.

Tim Cottee
0
 
MarvelousMerlinAuthor Commented:
Dhaest

There's no error.

TimCottee

I'll quickly try the before update

MM
0
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.

 
MarvelousMerlinAuthor Commented:
TimCottee

Stil doesn't update the DB.  Even with the Before update

MM
0
 
MarvelousMerlinAuthor Commented:
I've found that when i close the project the data gets updated.  and not during run-time.

??????

MM
0
 
MarvelousMerlinAuthor Commented:
sorry.......... when i STOP the project the data gets updated

MM
0
 
MarvelousMerlinAuthor Commented:
....no comments.......i'm battling with this one...plz help
0
 
DhaestCommented:
Take a look at the following:
PRB: DataBound Controls Not Updated with DataEnvironment Using Refresh Method
http://support.microsoft.com/default.aspx?scid=kb;en-us;216666&Product=vb6
0
 
MarvelousMerlinAuthor Commented:
Dhaest

Thanks for help.....didn't work.....
Changed to True DBGrid.  Working great.

But i'll splitt the spoints between you and TimCottee.  Just for ure effort.

THANKS

I've got another braintwister:  see if u could help plz:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21359729.html
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now