adodb connection
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: adodb connection

  1. #1
    Join Date
    Jul 2009
    Posts
    8

    adodb connection

    i have created textboxes for each fields available in an existing database file in a vb form.i need to show the data in the textboxes whenever i click the command buttons next and previous.help needed

  2. #2
    Join Date
    Jul 2009
    Location
    Brazil
    Posts
    25

    Re: adodb connection

    Why don't you use DBTextBOX?

  3. #3
    Join Date
    Jul 2009
    Posts
    8

    Re: adodb connection

    this is my code
    Private Sub Form_Load()

    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "datasource=E:\project1\databmdb;"
    cn.Open//shows error here

    str = "Select * from table"
    rs.Open str, cn








    Set Text1.DataSource = rs
    Text1.DataField = "NAME"
    end sub

  4. #4
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: adodb connection

    In your Open method you need

    cn.open (ConnectionString, optional username, optional password, optional options)

    So try this
    Dim cn as ADODB.Connection
    Dim rs as ADODB.Recordset
    dim strCN as string

    Set cn = new adodb.connection
    set rs = new adodb.recordset

    strCN = "Provider=Microsoft.Jet.OLEDB.4.0;" & "datasource=E:\project1\databmdb;"

    cn.open strCN

    rs.open "Select * from table", cn, adOpenStatic, adLockReadOnly (or whatever lock method you want)
    Last edited by arkansascontrols; July 22nd, 2009 at 10:26 AM.

  5. #5
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,844

    Re: adodb connection

    Personally I prefer not to bind the text boxes to a datasource. Typically I will use an array of text boxes and populate them in a loop

    for example if there are 10 fields in the RS and an array of 10 textboxes to be populated the code may look somethign like.

    Code:
    For x=0 to 9
        TextBox1(x).text=RS(x)
    Next
    Using this method the text box is not bound to the database so any changes to the data in the boxes do not have any effect on the database unless you write code to do so in your save routine. Basically the opposite of what is above

    Code:
    For x =0 to 9
       RS(x)=TextBox1(x).text
    Next

  6. #6
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: adodb connection

    I agree with DataMiser I don't like Data Controls or databound controls.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center