| |
|
Welcome to KnowledgeSutra - Dear Guest | |
Mysql In Visual Basic
Started by it01y2, May 23 2007 07:19 AM
14 replies to this topic
#2
Posted 31 May 2007 - 03:51 PM
It is quite possible to do that, I built several projects that connect to MySQL databases, one of them actually connecting to MySQL server here, on Trap17, on my hosted account... It works pefectly...
You need to download MyVbQL project, from Planet Source Code, and compile it into a dll, or include it directly in your project, and easily use it as a class...
Here's the link on Planet Source Code -> MyVbQL
Or a new project site: VbMySQL
Library has 4 classes:
MYSQL_CONNECTION -> Provides connectivity to MySQL server
MYSQL_RS -> Provides access to recordsets(tables) within MySQL database
MYSQL_FIELD -> Provides access to fields within MySQL table
MYSQL_ERR -> Provides access to error object, to see if any MySQL errors occured
You can access tables fields same as you would access a variable declared as a Collection:
Recordset.Fields("fieldname").Value
Recordset.Fields(fieldindex).Value
As the library is open source, when you get the source code, you will see all the properties of all four classes in the project... I'd recommend downloading it from PSC, as VbMySQL site didn't have a download available when I last looked at it...
Here's a small example how I use this great library in my projects:
If you need any help with this code, feel free to contact me... Happy connecting
You need to download MyVbQL project, from Planet Source Code, and compile it into a dll, or include it directly in your project, and easily use it as a class...
Here's the link on Planet Source Code -> MyVbQL
Or a new project site: VbMySQL
Library has 4 classes:
MYSQL_CONNECTION -> Provides connectivity to MySQL server
MYSQL_RS -> Provides access to recordsets(tables) within MySQL database
MYSQL_FIELD -> Provides access to fields within MySQL table
MYSQL_ERR -> Provides access to error object, to see if any MySQL errors occured
You can access tables fields same as you would access a variable declared as a Collection:
Recordset.Fields("fieldname").Value
Recordset.Fields(fieldindex).Value
As the library is open source, when you get the source code, you will see all the properties of all four classes in the project... I'd recommend downloading it from PSC, as VbMySQL site didn't have a download available when I last looked at it...
Here's a small example how I use this great library in my projects:
'Here I create a variable named MySQL as a new connection object for MySQL
Global MySQL As New MySQL_CONNECTION
Private Function MySQL_Connect() As Boolean
Dim res_MySQL As MYSQL_CONNECTION_STATE
MySQL_Connect = False
res_MySQL = MySQL.OpenConnection("server", "username", "password", "database", 3306, CLIENT_COMPRESS)
If res_MySQL = MY_CONN_OPEN Then
MySQL_Connect = True
End Function
' Query -> MySQL query to execute.
' CloseRS -> Optional. Close recordset created after executing Query.
' RS -> Optional. Reference to externaly created variable, declared as MYSQL_RS. If not closed, it will be available to the program after the query is executed.
' lAffected -> Optional. Numer of rows affected after te Query.
Public Sub SQLQuery(ByVal Query As String, Optional ByVal CloseRS As Boolean = False, Optional ByRef RS As MYSQL_RS, Optional ByRef lAffected As Long)
Dim ERR As MYSQL_ERR
Set RS = MySQL.Execute(Query, lAffected)
Set ERR = MySQL.Error
If ERR.Number <> 0 Then
' Handle any eventual errors that occurred during MySQL query
End If
ERR.Clear
Set ERR = Nothing
If CloseRS Then
RS.CloseRecordset
Set RS = Nothing
End If
End Sub
Public Sub DisplayData(ByRef RS As MYSQL_RS)
Dim p_Date As Date
If RS.RecordCount > 0 Then
p_Date = FromUnixTime(RS.Fields("date").value)
lblDate.Caption = Format(p_Date, "dd. mmmm yyyy")
txtTitle.Text = UTF8.UTF8ToANSI(RS.Fields("title").value)
txtDescription.Text = UTF8.UTF8ToANSI(RS.Fields("describe").value)
txtContent.Text = UTF8.UTF8ToANSI(RS.Fields("content").value)
End If
RS.CloseRecordset
Set RS = Nothing
End Sub
If you need any help with this code, feel free to contact me... Happy connecting
Edited by Galahad, 31 May 2007 - 04:05 PM.
#5
Posted 12 February 2008 - 09:58 AM
FeedBacker, on Feb 9 2008, 04:36 PM, said:
Question
Mysql In Visual Basic
Are codes for linking vb 6.0 form to all versions of sql same?
-question by asogol
Mysql In Visual Basic
Are codes for linking vb 6.0 form to all versions of sql same?
-question by asogol
If I understood you correctly, you want to link entire form to a database object? Well, that is not possible with MySQL library I mentioned above, but I suppose it could be done using ADO... Only, I don't like to use ADO, so I can't help you with that, but at least I can give you that pointer - look for it using ADO...
Although, I don't see why one wouldn't use this library, it's small, fast, and it works... As far as I know it connects to MySQL 4.x and 5.x, possibly even 3.x... It all depends on MySQL maintaining libmysql.dll compatibility, and keeping all the functions within...
It does take some programming to display and update the data from MySQL, but hey, you can't have it all with zero effort...
Reply to this topic

1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users














