CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2012
    Posts
    13

    How to update a record from a Flex Grid?

    okay.

    Here's my problem.
    I have a form in which a Microsoft Hierarchical Flex Grid (fgdCompany) is used to display records taken from a database to relevant textboxes on the same form.
    When a record from fgdCompany is clicked, then the data in that record is shown on the textboxes.
    I have a button called cmdUpdate which should do the following when clicked :
    Once, the record is displayed on the text boxes, a change could be made to it.
    And when cmdUpdate is clicked it should save the changes it made to that record and display the new updated record on fgdCompany.
    My problem is, it always saves the changes made to the first record in fgdCompany. Not the record I want to be changed.
    Please help me..... Code used for cmdUpdate is given below.

    Code:
      Dim rsCompany As New ADODB.Recordset
      Dim cn As New ADODB.Connection
      Dim strSQL As String
      
      cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                            "Data Source=" & App.Path & "\Luckshan Tours & Travels.mdb;" & _
                            "Persist Security Info:False"
                          
      cn.Open
       
      strSQL = "SELECT [Company].* FROM [Company]"
      rsCompany.Open strSQL, cn, adOpenStatic, adLockPessimistic
      
      rsCompany.Fields("Address") = txtAddress
      rsCompany.Fields("Telephone Numbers") = txtTelephoneNo
      rsCompany.Fields("Vehicles Registered") = txtVehiclesReg
      
      rsCompany.Update
      
      MsgBox "Changes Saved."
      
      Set fgdCompany.DataSource = rsCompany
      
      rsCompany.Update

  2. #2
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: How to update a record from a Flex Grid?

    You're having the same problem as your delete code. The solution will look very similar to the code given that made the delete work.

  3. #3
    Join Date
    Jun 2012
    Posts
    13

    Re: How to update a record from a Flex Grid?

    You're having the same problem as your delete code. The solution will look very similar to the code given that made the delete work.
    I tried it but it didn't work. Can you please send me the code that would work! =)
    Would be helping me greatly buddy!!

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to update a record from a Flex Grid?

    You are selecting ALL of the records in the table.

    [Company].*

    Select the Fields that you will affect. [Company].Address [Company].TelephoneNumber (bad to have a space in field name)

    Then, look up a WHERE clause. Where and the Record to update. [Company].RecNum = 42

    Then, your code will update THAT record.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured