Retreaving and displaying records from MySQL Database

Posted on 2003-03-06
Medium Priority
Last Modified: 2010-05-18
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!

Question by:mike_higgins
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8080971
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.  
LVL 16

Accepted Solution

Richie_Simonetti earned 100 total points
ID: 8081171
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

Author Comment

ID: 8081669
Asmodius, I am new at Database progrmming, could you give me an example in code perhaps?

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 8081860
Asmodius, I am new at Database progrmming, could you give me an example in code perhaps?
LVL 11

Assisted Solution

supunr earned 100 total points
ID: 8084285
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!

Author Comment

ID: 8166552
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????

Expert Comment

ID: 8900561
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?
LVL 49

Expert Comment

ID: 9074210
Moderator, my recommended disposition is:

    Split points between: Richie_Simonetti and supunr

DanRollins -- EE database cleanup volunteer

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question