Loading...


bookmark - Mysql In Visual Basic Mysql in visual basic

Mysql In Visual Basic - Mysql in visual basic

 
 Discussion by it01y2 with 14 Replies.
 Last Update: June 16, 2011, 2:03 am
 
bookmark - Mysql In Visual Basic Mysql in visual basic  
Quickly Post to Mysql In Visual Basic Mysql in visual basic w/o signup Share Info about Mysql In Visual Basic Mysql in visual basic using Facebook, Twitter etc. email your friend about Mysql In Visual Basic Mysql in visual basic Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

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

Any ideas?












   Wed May 23, 2007    Reply         

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

   Thu May 31, 2007    Reply         

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

thanks,
Xp10r3r_3X

   Tue Jun 19, 2007    Reply         


Question
Mysql In Visual Basic

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

-question by asogol

   Sat Feb 9, 2008    Reply         

QUOTE (FeedBacker)

Question

Mysql In Visual Basic
Are codes for linking vb 6.0 form to all versions of sql same?

-question by asogol
Link: view Post: 373101


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

   Tue Feb 12, 2008    Reply         

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

   Mon Apr 7, 2008    Reply         


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.

   Tue Mar 10, 2009    Reply         

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

 

   Mon Mar 30, 2009    Reply         

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

   Wed Sep 30, 2009    Reply         

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,

   Mon Dec 21, 2009    Reply         

VB Login form Mysql In Visual Basic

Hi

I would like to know how to create source code for login form in VB and how to link VB with SQL I'm busy doing project right now Please help 

-reply by Masibulele

   Wed Feb 24, 2010    Reply         

QUOTE (it01y2)


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

Any ideas?

Link: view Post: 326093


Answer:
Create a new project. Add a button called Command1.
Paste the code below into the project.
Edit any text between < and > to the appropriate values.
Also, go to the dropdown menu Project/References - and select "Microsoft ActiveX Data Objects 2.0 Library" and click OK.
Download and install - "mysql-connector-odbc-3.51.27-win32.msi"
When you run the project, it will display a message box displaying the content of each record's selected field in turn.
Use the commented out loop bit to restrict the amount of results or to avoid unwanted loops.
It's pretty basic but it works.

Dim strDatabaseName As String
Dim strDBCursorType As String
Dim strDBLockType As String
Dim strDBOptions As String
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection

Private Sub Command1_Click()
On Error GoTo 9
Dim strSQL As String
Dim X As Long
strDBCursorType = adOpenDynamic 'CursorType
strDBLockType = adLockOptimistic 'LockType
strDBOptions = adCmdText 'Options

Set cn = New ADODB.Connection
Me.MousePointer = 11 'sets pointer to hourglass
cn.Open ConnectString()
With cn
.CommandTimeout = 0
.CursorLocation = adUseClient
End With
Set rs = New ADODB.Recordset 'Creates record set
strSQL = "select * from <your table>"
rs.Open strSQL, cn, strDBCursorType, strDBLockType, strDBOptions
If Not rs.BOF Then
rs.MoveFirst
End If
If rs.EOF Then
MsgBox "No data found"
Else
For X = 1 To rs.RecordCount
MsgBox rs.Fields("<your field>").Value
rs.MoveNext
'If X > 100 Then GoTo 10 'use this to avoid getting stuck in loops during development
Next X
rs.Close
Me.MousePointer = 0 'sets pointer to normal
End If
GoTo 10
9
MsgBox "Error - I'm out of here!"
10
End Sub

Private Function ConnectString() As String
Dim strServerName As String
Dim strDatabaseName As String
Dim strUserName As String
Dim strPassword As String

'Change to IP Address if not on local machine
strServerName = "localhost"
strDatabaseName = "<your database name>"
strUserName = "<your username>"
strPassword = "<Your password>"

ConnectString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=" & strServerName & _
";DATABASE=" & strDatabaseName & ";" & _
"USER=" & strUserName & _
";PASSWORD=" & strPassword & _
";OPTION=3;"

End Function

   Sat Jan 1, 2011    Reply         

Galahad

Could you supply another location or way of getting your files for this post?
Planetsoucecode is producing vb script errors when I try to register.

   Thu Feb 17, 2011    Reply         

while using VB 6.0 you can interact with the mysql using database connectivity to your application

you have create a tables in Microsoft Access & then open the visual basic application window using connnection string properties

you can write sql query in your application code you will get the excepted result that you want in the application

for e.g if you want to retriew the list customers table

"select * from customers "

   Tue Mar 1, 2011    Reply         

Dear Sir /Madam!

I tried to insert data into mysql database using vb.net 2008. When i click Save Button it Showing Error message"There is No Source Code Available in Current Location!"Please Tell me Solution for my Problem.

   Thu Jun 16, 2011    Reply         

Quickly Post to Mysql In Visual Basic Mysql in visual basic w/o signup Share Info about Mysql In Visual Basic Mysql in visual basic using Facebook, Twitter etc. email your friend about Mysql In Visual Basic Mysql in visual basic Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Similar Topics:

Can Php Interact With A Visual Basi...

I am currently making a game. And I want to use a command through php to ineract with a visual basic app on my server. Is it possible? and how? ...more

   14-Nov-2006    Reply         

Visual Basic For The Web?

Ok, I have heard that you can use Visual Basic to create websites and I have found controls for the web inside of my VB 2005 Express Edition, and I am curious as to how I would use these and create applications for websites? I know there is ASP.NET, but how is VB.NET used on the web? I do know PHP i ...more

   17-Jan-2009    Reply         

Can you give me a sample visual bas...

Can you give me a sample visual basic system?Creating A Timer ProgramWell, we're starting up with Visual Basic now.. It seems difficult.. But because of our background with Qbasic it's easier to understand its dynamics...I would like to ask for a sample Visual Basic system that I co ...more

   24-Jan-2010    Reply         

Find Prime Number find prime number code   Find Prime Number find prime number code (4) (3) Simple Message Box   Simple Message Box