Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Mysql In Visual Basic, Mysql in visual basic
it01y2
post May 23 2007, 07:19 AM
Post #1


Member [Level 1]
****

Group: Members
Posts: 65
Joined: 7-July 05
Member No.: 9,139



I'm am trying to create a script so that visual basic 6 can interact with mysql

Any ideas?
Go to the top of the page
 
+Quote Post
Galahad
post May 31 2007, 03:51 PM
Post #2


Neurotical Squirrel
*********

Group: [HOSTED]
Posts: 587
Joined: 4-November 04
From: Novi Sad, Vojvodina
Member No.: 2,127



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:

CODE
'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 smile.gif

This post has been edited by Galahad: May 31 2007, 04:05 PM
Go to the top of the page
 
+Quote Post
xplorer-ex
post Jun 19 2007, 11:02 AM
Post #3


Newbie [Level 1]
*

Group: Members
Posts: 17
Joined: 19-June 07
Member No.: 45,058



thanks for that post, i will also find this handy. i could use this in a future project of mine

thanks,
Xp10r3r_3X
Go to the top of the page
 
+Quote Post
iGuest
post Feb 9 2008, 03:36 PM
Post #4


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



Question
Mysql In Visual Basic

Are codes for linking vb 6.0 form to all versions of sql same?

-question by asogol
Go to the top of the page
 
+Quote Post
Galahad
post Feb 12 2008, 09:58 AM
Post #5


Neurotical Squirrel
*********

Group: [HOSTED]
Posts: 587
Joined: 4-November 04
From: Novi Sad, Vojvodina
Member No.: 2,127



QUOTE(FeedBacker @ Feb 9 2008, 04:36 PM) *
Question

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...
Go to the top of the page
 
+Quote Post
iGuest
post Apr 7 2008, 07:03 AM
Post #6


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



about View,function,preceddure
Mysql In Visual Basic

I want to develop one project in vb and mysql and now I want to use view,function and procedure so plese help me and give me a code if it is possible thanking you

-question by Ashish Dudhatra
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. [tutorial] Visual Basic 6 Downloading Images From A Webpage(2)
  2. [tutorial] Visual Basic 6 Minimize To Tray(4)
  3. Lost Connection To Mysql Server During Query [(1)
  4. Linking To Mysql From Vb(6)
  5. Visual Basic 6.0 Help Needed(13)
  6. Visual Basic Express Edition Beta(2)
  7. Visual Basic 6(5)
  8. Visual Basic And Internet Transmission(2)
  9. Some Visual Basic 6.0 Uncompleted Projects(2)
  10. My Guidewriter(3)
  11. Beginning Visual Basic(4)
  12. Vb Select Mysql Database(2)


 



- Lo-Fi Version Time is now: 27th July 2008 - 01:37 AM