|
|
Mysql In Visual Basic - Mysql in visual basic | ||
Discussion by it01y2 with 14 Replies.
Last Update: June 16, 2011, 2:03 am | |||
![]() |
|
|
Any ideas?
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 MySQLGlobal 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
thanks,
Xp10r3r_3X
Mysql In Visual Basic
Are codes for linking vb 6.0 form to all versions of sql same?
-question by asogol
QUOTE (FeedBacker)
QuestionMysql 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...
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
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.
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
...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
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,
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
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
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.
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 "
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.
Similar Topics:
Can Php Interact With A Visual Basi...
Visual Basic For The Web?
Can you give me a sample visual bas...
Find Prime Number find prime number code (4)
|
(3) Simple Message Box
|
Loading...
HOME 





Visual Basic Programming Tutorial - Connecting to a MySQL Database with VB.NET Using ADO.NET
How to: VB.NET VB2010 Connecting to MySQL Database and inserting record
Visual basic mysql login
How to connect to a MySQL server database VB NET VB.NET VB6 Visual Basic
#3 Mysql Connection Vb 9.0 VB.net

