Full Module Code: Imports MySql.Data.MySqlClient Module SQL 'Setup a new MySQLConnection Public Connection As New MySqlConnection 'Dim Command so we can execute sql commands Dim Command As MySqlCommand Public Sub ConnecttoDB() Try 'we are setting the username, password, ect Connection = New MySqlConnection(String.Format("server={0};user id={1}; password={2}; port=3306; database={3}; pooling=false", Login.txtServer.Text, Login.txtUser.Text, Login.txtPass.Text, Login.txtDB.Text)) 'okay now everything is set lets connect, if there is a problem is goes down to line 17 Connection.Open() Main.Show() Login.Close() Catch mysql As MySqlException 'displays whatever went wrong from Connection.Open() MsgBox(mysql.Message) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Public Sub FillData(ByVal Table As String, ByRef Output As DataTable) Try 'Setting up a new command to grab all the data from the table the user inputs, limits the items to 100 so it doesnt laggg Command = New MySqlCommand("SELECT * FROM `" & Table & "` LIMIT 100;", Connection) 'this fills all the data that was inside the command that was executed, into MySqlA Dim MySqlA As New MySqlDataAdapter(Command) 'puts all the info from the database into the datatable Output MySqlA.Fill(Output) 'if the rows count = 0 then that means there is no data so set the datatable to = nothing If Output.Rows.Count = 0 Then Output = Nothing End If Catch e As MySqlException MsgBox(e.Message) End Try End Sub GRAB BUTTON CODE Dim Output As New DataTable If txttable.Text = "" Then MsgBox("Select a table to get the data from") : Exit Sub End If view.DataSource = Nothing FillData(txttable.Text, Output) If Output Is Nothing Then MsgBox("No data") Else view.DataSource = Output End If LOGIN BUTTON CODE Public Class Login Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click ConnecttoDB() End Sub End Class code pour embarquer la vidéo : >>> http://www.youtube.com/embed/2cszI04Gyew <<< |