Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Mysql In Visual Basic


14 replies to this topic

#1 it01y2

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 71 posts

Posted 23 May 2007 - 07:19 AM

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

Any ideas?

#2 Galahad

    Neurotical Squirrel

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 590 posts
  • Gender:Male
  • Location:Novi Sad, Vojvodina
  • Interests:Programming, Hardcore dance/Trance/House music. Girls, girls and more girls ;) ... In short, everything youg people like, I like :D Oh yeah, and dont't forget politics :)
  • myCENT:48.25

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:

'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 :lol:

Edited by Galahad, 31 May 2007 - 04:05 PM.


#3 xplorer-ex

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 18 posts

Posted 19 June 2007 - 11:02 AM

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

thanks,
Xp10r3r_3X

#4 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 09 February 2008 - 03:36 PM

Question
Mysql In Visual Basic

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

-question by asogol

#5 Galahad

    Neurotical Squirrel

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 590 posts
  • Gender:Male
  • Location:Novi Sad, Vojvodina
  • Interests:Programming, Hardcore dance/Trance/House music. Girls, girls and more girls ;) ... In short, everything youg people like, I like :D Oh yeah, and dont't forget politics :)
  • myCENT:48.25

Posted 12 February 2008 - 09:58 AM

View PostFeedBacker, 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

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...

#6 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 07 April 2008 - 07:03 AM

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

#7 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 11 March 2009 - 06:46 AM

Components / References Mysql In Visual Basic

Usually if we want to connect a database into VB we must add some components or references right?I'm wondering what components or references that we must add into the VB for using VB and MySQL.



#8 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 30 March 2009 - 10:18 AM

using MyVbQL with VB6Mysql In Visual Basic

Hi there..

I tried your code snippet but I get this error: Not Found: libmySQL

 I've already copied the dll to the system32 folder and regsvr32 it. Anything that I missed?

 Thanks

-question by boddah

 



#9 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 30 September 2009 - 11:18 PM

...I have a project regarding the use of mysql, I have to make a database combined with visual basic 6.0, can you help me within this week?tnx...

-question by lyka

#10 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 21 December 2009 - 09:15 AM

can you give me some examples on how to connect MySQL to vb6.0?, is it possible to use this as my database??,,hope that I can get your answer ASAP,, thnx for reading,






Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users