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

x
  • 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='';"
cnMySql.EstablishConnection

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!
Thanks


0
mike_higgins
Asked:
mike_higgins
2 Solutions
 
AsmodiusCommented:
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.  
0
 
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
 txt2.text=.Fields(1)
 txt3.text=.Fields(2)
 '... and so on
end with
end sub
0
 
mike_higginsAuthor Commented:
Asmodius, I am new at Database progrmming, could you give me an example in code perhaps?
Thanks!
0
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?
Thanks!
0
 
supunrCommented:
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!
0
 
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????
0
 
CleanupPingCommented:
mike_higgins:
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?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Split points between: Richie_Simonetti and supunr

DanRollins -- EE database cleanup volunteer
0

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