The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Visual Basic Programming
|
VB en Mysql(?)(?)(?)
Discuss VB en Mysql(?)(?)(?) in the Visual Basic Programming forum on Dev Shed. VB en Mysql(?)(?)(?) Visual Basic Programming forum discussing VB specific programming information. Quickly prototype and build applications with this robust and simple language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 27th, 2003, 12:53 PM
|
|
Junior Member
|
|
Join Date: Apr 2003
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
VB en Mysql(?)(?)(?)
is it possible to use Mysql in VB projects? and ifso how?
greetz JJ
|

April 27th, 2003, 09:09 PM
|
|
Junior Member
|
|
Join Date: Mar 2002
Location: Portland, Oregon USA
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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
|

April 28th, 2003, 03:12 AM
|
|
Junior Member
|
|
Join Date: Apr 2003
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
and how can i use query's then?
|

April 28th, 2003, 08:41 AM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
|
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.
|

April 28th, 2003, 09:04 AM
|
|
Junior Member
|
|
Join Date: Apr 2003
Posts: 6
Time spent in forums: < 1 sec
Reputation 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 ;-)
|

April 28th, 2003, 09:42 AM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
|
have you used the adodb object before?
|

April 28th, 2003, 09:45 AM
|
|
Junior Member
|
|
Join Date: Apr 2003
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Nope 
|

April 28th, 2003, 09:48 AM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
|

April 28th, 2003, 09:50 AM
|
|
Junior Member
|
|
Join Date: Apr 2003
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
thnx
JJ
|

April 28th, 2003, 02:05 PM
|
|
Junior Member
|
|
Join Date: Mar 2002
Location: Portland, Oregon USA
Posts: 2
Time spent in forums: < 1 sec
Reputation 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 --
|

April 29th, 2003, 01:20 PM
|
 |
echo $usertitle['computer'];
|
|
Join Date: Jan 2003
Location: UK
|
|
|
my turn to ask :p
ok so how would I add something from some textboxes into a new record on a DB?
|

April 29th, 2003, 02:24 PM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
|
sql = "insert into your_table values ('" & textbox1.text & "')"
objConnection.Execute sql
this is assuming that your_table only has one column
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|