|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
is it possible to use Mysql in VB projects? and ifso how?
greetz JJ |
|
#2
|
|||
|
|||
|
Yes it is. You'll first need to have the MyODBC driver installed on your system. It can be found here:
URL 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 |
|
#3
|
|||
|
|||
|
and how can i use query's then?
|
|
#4
|
||||
|
||||
|
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.
|
|
#5
|
|||
|
|||
|
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 ;-)
|
|
#6
|
||||
|
||||
|
have you used the adodb object before?
|
|
#7
|
|||
|
|||
|
Nope
![]() |
|
#8
|
||||
|
||||
|
I would suggest some reading here:
http://search.microsoft.com/default...9&siteid=us/dev |
|
#9
|
|||
|
|||
|
thnx
JJ |
|
#10
|
|||
|
|||
|
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 -- |
|
#11
|
||||
|
||||
|
my turn to ask :p
ok so how would I add something from some textboxes into a new record on a DB?
|
|
#12
|
||||
|
||||
|
sql = "insert into your_table values ('" & textbox1.text & "')"
objConnection.Execute sql this is assuming that your_table only has one column |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > VB en Mysql(?)(?)(?) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|