Created
August 31, 2016 08:55
-
-
Save freretuc/ccd55c3c223bcff0da0b7fbed57e3685 to your computer and use it in GitHub Desktop.
vb.net MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports MySql.Data.MySqlClient | |
Public SQLServer As New MySqlConnection | |
Public Sub SQLOpen() | |
Try | |
If Not SQLServer Is Nothing Then SQLServer.Close() | |
Catch ex As Exception | |
End Try | |
SQLServer.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", SQLHost, SQLUser, SQLPassword, SQLDatabase) | |
Try | |
SQLServer.Open() | |
Catch ex As Exception | |
MsgBox(ex.Message) | |
End Try | |
End Sub | |
Public Sub SQLClose() | |
If Not SQLServer Is Nothing Then SQLServer.Close() | |
End Sub | |
Public Sub Test() | |
Dim deviceSet As New DataSet | |
If Not SQLServer.State = ConnectionState.Open Then SQLOpen() | |
Try | |
Dim data As New MySqlDataAdapter | |
data.SelectCommand = New MySqlCommand("SELECT * FROM blablabla", SQLServer) | |
data.Fill(deviceSet) | |
For Each _row As Data.DataRow In deviceSet.Tables(0).Rows 'Tables(0) = première table (il n'y en a qu'une) | |
msgbox(_row.Item("did")) | |
Next | |
Catch ex As Exception | |
Console.WriteLine(ex.Message) | |
End Try | |
SQLClose() | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment