Jump to content
xisto Community
Sign in to follow this  
it01y2

Mysql In Visual Basic Mysql in visual basic

Recommended Posts

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 Xisto, 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 MySQLGlobal MySQL As New MySQL_CONNECTIONPrivate Function MySQL_Connect() As BooleanDim res_MySQL As MYSQL_CONNECTION_STATEMySQL_Connect = Falseres_MySQL = MySQL.OpenConnection("server", "username", "password", "database", 3306, CLIENT_COMPRESS)If res_MySQL = MY_CONN_OPEN Then  MySQL_Connect = TrueEnd 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 IfEnd SubPublic 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 = NothingEnd Sub

If you need any help with this code, feel free to contact me... Happy connecting :lol:

Edited by Galahad (see edit history)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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


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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

while using VB 6.0 you can interact with the mysql using database connectivity to your applicationyou 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 applicationfor e.g if you want to retriew the list customers table "select * from customers "

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.