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

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

Retreaving and displaying records from MySQL Database

Ok, I am connecting to my database using this code:

Dim cnMySql As New rdoConnection
Dim rdoQuery As New rdoQuery
Dim rdoResultSet As rdoResultSet

' set up a remote data connection using the
' MySQL ODBC driver.
cnMySql.CursorDriver = rdUseOdbc
cnMySql.Connect = "uid=root;pwd=;server=localhost;" & _
    "driver={MySQL ODBC 3.5Driver};database=MyDatabase;dsn='';"

Ok, I'm inserting a query into my database like this:

With rdoQuery
    .Name = "addCustomer"
    .SQL = "<insert query>"
    .RowsetSize = 1
    Set .ActiveConnection = cnMySql
    Set rdoRS = .OpenResultSet(rdOpenKeyset, rdConcurRowVer)
End With

Now what I am trying to figure out is how to select a single record and seperate each field into seperate text boxes in my application.

Any help is greatly appreciated!

2 Solutions
I was wondering why you don't just use a datacontrol and bound text boxes?

If it is because you are creating the query as you go, then what you CAN do is create the query, then set the datasource for the bound control to the new query.  Then you will have to go and set each text boxes datasource to the appropriate field on the datacontrol.  
Richie_SimonettiIT OperationsCommented:
You need to create the navigation buttons (Next, previos, First,last) by yourself.
On every click of those buttons, you need to call a sub like this:

sub PopulateTxt(rs as recordset)
with rs
 txt1.text=.Fields(0)   ' better if you use an array of text boxes
 '... and so on
end with
end sub
mike_higginsAuthor Commented:
Asmodius, I am new at Database progrmming, could you give me an example in code perhaps?
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.

mike_higginsAuthor Commented:
Asmodius, I am new at Database progrmming, could you give me an example in code perhaps?
Private Sub LoadValues(rs as Recordset)
    ' exit if the recordset is not open
    if (rs.State = adStateClose) then Exit Sub
    ' exit if recordset is pointing to the end of start
    if (rs.EOF or rs.BOF) then Exit Sub

    txtValues(0).Text = "" & rs.Fields("FieldName1").Value
    txtValues(1).Text = "" & rs.Fields("FieldName2").Value
    txtValues(2).Text = "" & rs.Fields("FieldName3").Value
    txtValues(3).Text = "" & rs.Fields("FieldName4").Value
    ' etc...
End Sub

Privat Sub SomeOtherFunction()
   ' Open Recordset rdoRS
   LoadValues rdoRS
End Sub

reson for adding "" & before asignment is to get rid of null assignments in case the recordset value is null.

Good Luck!
mike_higginsAuthor Commented:
Ok, so I'm using an RDO data connection.  Might there be a more simple way to connect, insert, and select records from my MySQL database.  Perhaps a VB wizard that simplifies the connection and syntax????
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
Moderator, my recommended disposition is:

    Split points between: Richie_Simonetti and supunr

DanRollins -- EE database cleanup volunteer

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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