Mysql in visual basic Sample Source Code
Posted by rodolfo_panganiban on 21 January, 2010
No comments yet
This item was filled under [ FREE SOURCE CODE, Visual Basic 6.0 ]
'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
Popularity: 1,780 views



