#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    6
    Rep Power
    0

    Question VB en Mysql(?)(?)(?)


    is it possible to use Mysql in VB projects? and ifso how?

    greetz JJ
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Portland, Oregon USA
    Posts
    2
    Rep Power
    0
    Yes it is. You'll first need to have the MyODBC driver installed on your system. It can be found here:

    http://www.mysql.com/products/myodbc/index.html

    Then the following code (Assuming you've set a reference to use ADODB controls):

    -- Begin Code --

    Set objConnection = New ADODB.Connection

    objConnection.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=your_server_name_here;DATABASE=your_database_name_here;UID=username_here;PWD=password _here; OPTION=16427 "

    objConnection.Open

    -- End Code --

    Hope that helps,

    jhb
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    6
    Rep Power
    0
    and how can i use query's then?
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    Once you have the MyODBC driver installed and you establish an adodb connection as jhb posted, then you just use it as you would any adodb object.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    6
    Rep Power
    0
    i haven't used them before :$, i've made some complicated programs but so far only stand alone. this is the first i will use with a out-source program ;-)
  10. #6
  11. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    have you used the adodb object before?
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    6
    Rep Power
    0
    Nope
  14. #8
  15. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    6
    Rep Power
    0
    thnx

    JJ
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Portland, Oregon USA
    Posts
    2
    Rep Power
    0

    Here's my DataAccess class and implementation (I use arrays instead of recordsets)


    -- Begin cDataAccess Class --

    Option Explicit
    Private objConnection As ADODB.Connection

    Public Function RetrieveData(strSQL As String) As Variant

    Dim objRecordset As ADODB.Recordset

    'send the query to the database and return data to a Recordset object
    Set objRecordset = objConnection.Execute(strSQL)

    'we need to convert the recordset into an array and send it back to the calling
    'only convert to an array if there is something in the recordset
    If objRecordset.BOF = False Or objRecordset.EOF = False Then
    RetrieveData = objRecordset.GetRows
    End If

    End Function

    Public Sub Update(strSQL As String)

    objConnection.Execute strSQL

    End Sub

    Public Sub Disconnect()

    objConnection.Close
    Set objConnection = Nothing

    End Sub


    Public Sub Connect()

    Set objConnection = New ADODB.Connection

    'Driver version needs to match version you installed
    objConnection.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=your_server_name_here;DATABASE=your_database_name_here;UID=username_here;PWD=password _here; OPTION=16427 "

    objConnection.Open


    End Sub

    -- End cDataAccess Class --

    And how it would be used to bring back an array...

    -- Begin Code --

    Private mobjDataAccess As cDataAccess

    Set mobjDataAccess = New cDataAccess

    Public Function GetSomeData() As Variant

    Dim strSQL As String

    strSQL = "SELECT id,name from sometable"

    mobjDataAccess.Connect

    GetSomeData = mobjDataAccess.RetrieveData(strSQL)

    mobjDataAccess.Disconnect

    Set mobjDataAccess = Nothing

    End Function

    -- End Code --

    And how to loop through that array and fill up a list box (assuming your bringing back an array with two items...for example... an id and a name)

    -- Begin Code --

    Public Sub FillSomeListBox()

    Dim intCounter As Integer
    Dim arrSomeList As Variant

    arrSomeList = GetSomeData()

    For intCounter = 0 To UBound(arrSomeList, 2)

    lstSomeListBox.AddItem arrSomeList(1, intCounter)

    lstSomeListBox.ItemData(lstSomeListBox.NewIndex) = arrSomeList(0, intCounter)
    Next

    End Sub

    -- End Code --
  20. #11
  21. echo $usertitle['computer'];
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    UK
    Posts
    6,705
    Rep Power
    420

    my turn to ask :p


    ok so how would I add something from some textboxes into a new record on a DB?
  22. #12
  23. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    sql = "insert into your_table values ('" & textbox1.text & "')"
    objConnection.Execute sql

    this is assuming that your_table only has one column

IMN logo majestic logo threadwatch logo seochat tools logo