Results 1 to 9 of 9

Thread: [VB6] - using data control

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    [VB6] - using data control

    i'm trying understand how can i edit records, but i can't find the information
    can anyone advice me?
    if i use the update with an existed record, i get errors
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: [VB6] - using data control

    Well you are best off not to use the data control at all. Better to write ADO code.
    There are also some issues with bound controls in VB6 that make those better avoided as well.

    As for how to edit records that depends on what you have done with the data control

    You need to tell us what the errors are before we can tell you how to avoid/correct them

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB6] - using data control

    Quote Originally Posted by DataMiser View Post
    Well you are best off not to use the data control at all. Better to write ADO code.
    There are also some issues with bound controls in VB6 that make those better avoided as well.

    As for how to edit records that depends on what you have done with the data control

    You need to tell us what the errors are before we can tell you how to avoid/correct them
    heres my actual code:

    Code:
    Option Explicit
    
    Private Sub cmdFind_Click()
        Dim s As String
        s = InputBox("insira a matricula")
        Data1.Recordset.FindFirst "Matricula = '" & s & "'"
        If Data1.Recordset.NoMatch Then
            MsgBox "Not found"
        End If
    End Sub
    
    Private Sub cmdMoveNext_Click()
        If Data1.Recordset.EOF = True Then Data1.Recordset.MoveLast
        frmVeiculos.Caption = Data1.Recordset.AbsolutePosition
    End Sub
    
    Private Sub cmdNew_Click()
        Data1.Recordset.AddNew
    End Sub
    
    Private Sub cmdPrevious_Click()
        If Data1.Recordset.BOF = True Then Data1.Recordset.MoveFirst
        frmVeiculos.Caption = Data1.Recordset.AbsolutePosition
    End Sub
    
    Private Sub cmdPrinter_Click()
        frmVeiculos.PrintForm
    End Sub
    
    Private Sub cmdSave_Click()
        Data1.Recordset.Update
    End Sub
    
    Private Sub Command1_Click()
        Data1.Recordset.Delete
        Data1.Refresh
    End Sub
    i'm having problems for save and edit
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: [VB6] - using data control

    You are not giving us much to go on, "having problems" could mean almost anything. Be more specific. What problems, what errors?

    I assume you are using bound controls?

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB6] - using data control

    Quote Originally Posted by DataMiser View Post
    You are not giving us much to go on, "having problems" could mean almost anything. Be more specific. What problems, what errors?

    I assume you are using bound controls?
    sorry, what is 'bound controls'?(my english is limited)
    instead tell what are the problems.. correct me, if i'm wrong:
    1 - for save i use Data1.Recordset.Update right?
    2 - but how can i edit the record?
    (maybe these is my big problem)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: [VB6] - using data control

    Bound controls is when you set the data source of say a text box to a data control or a recordset object.

    When a textbox is bound to a datasource then that text box automatically displays the data from the data source, likewise when you change the data in the textbox you are affecting the datasource that it is bound to.

    So to edit data when using bound textboxes you simply edit the text in the text box and then use the .Update method of the recordset to save to the database.

    One of the many issues with bound controls is that if you change some data in a text box and move to the next record it will want to save your change wether you want it to or not.

    Personally I do not use the data control nor do I ever use bound text boxes. Yes it is easier for the programmer to try the form together with bound controls and yes it requires a lot more code to not bind them but the results are much better and you have full control over what happens.

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB6] - using data control

    Quote Originally Posted by DataMiser View Post
    Bound controls is when you set the data source of say a text box to a data control or a recordset object.

    When a textbox is bound to a datasource then that text box automatically displays the data from the data source, likewise when you change the data in the textbox you are affecting the datasource that it is bound to.

    So to edit data when using bound textboxes you simply edit the text in the text box and then use the .Update method of the recordset to save to the database.

    One of the many issues with bound controls is that if you change some data in a text box and move to the next record it will want to save your change wether you want it to or not.

    Personally I do not use the data control nor do I ever use bound text boxes. Yes it is easier for the programmer to try the form together with bound controls and yes it requires a lot more code to not bind them but the results are much better and you have full control over what happens.
    so what you can advice me for do a data base programs?
    (you can give me a nice link tutorial?)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: [VB6] - using data control

    There are lots of tutorials out there. I would have to search to find one so that is not something you could not do yourself with a little effort, You may even be able to find one in your native language and be able to understand it better.

    I would advise using ADO Code rather than the data control, tons of examples out there and easier to get help on that since not many actually use the data control. Same for bound controls in most cases it is better to write code to populate the controls and update the database rather than rely on the automagic abilities of the bound controls.

    You may want to have a look here in the code bank, I am sure there are some examples of how to work with a database.

  9. #9
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: [VB6] - using data control

    I've posted two demos recently, which show a good compromise IMO...

    They use DataBinding (less code in your Forms with regards to synchronizing the TextBox-contents),
    but work more near the metal with regards to the underlying Events which trigger the actions on
    these bound controls (using ADO-Recordset directly instead of the ADO-DataControl).

    take a look here:
    http://www.vbforums.com/showthread.p...=1#post4653483

    The link to the simpler Demo is also mentioned in this post - maybe start with that first...

    Olaf

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