Good
nice
'Represents an SQL statement or stored procedure to execute against a data source. Dim cmd As New MySqlCommand Dim da As New MySqlDataAdapter Public total As Integer Dim publictable As New DataTable 'declare conn as connection and it will now a new connection because 'it is equal to Getconnection Function Dim con As MySqlConnection = jokenconn() Public Function jokenconn() As MySqlConnection Return New MySqlConnection("server=localhost;user id=root;password=;database=") End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sql As String = "SHOW DATABASES" Dim publictable As New DataTable Try 'bind the connection and query With cmd .Connection = con .CommandText = sql End With da.SelectCommand = cmd da.Fill(publictable) With cbdb .DataSource = publictable .DisplayMember = "Database" .ValueMember = "Database" End With da.Dispose() Catch ex As Exception End Try con.Clone() End Sub
Private Sub btntest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntest.Click Dim sql As String = "SHOW TABLES FROM " & cbdb.Text Dim publictable As New DataTable Try 'bind the connection and query With cmd .Connection = con .CommandText = Sql End With da.SelectCommand = cmd da.Fill(publictable) ' publictable.Rows.Add("Please Select...") With lstfield .DataSource = publictable .DisplayMember = "Tables_in_" & cbdb.Text .ValueMember = "Tables_in_" & cbdb.Text End With ' dtgrd.Columns(1).Visible = False da.Dispose() Catch ex As Exception End Try con.Clone() End Sub
Private Sub btngo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngo.Click Dim publictable As New DataTable Dim sql As String sql = txtquery.Text Try 'bind the connection and query With cmd .Connection = con .CommandText = sql End With 'Gets or sets a Transact-SQL statement or stored procedure used to select records in the data source. da.SelectCommand = cmd da.Fill(publictable) 'get the datasource from publictable and passed to datagridview dtresultview.DataSource = publictable 'dispose the dataadapter da.Dispose() Catch ex As Exception End Try da.Dispose() End Sub
Private Sub lstfield_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstfield.Click txtquery.Text = "SELECT * FROM " & cbdb.Text & "." & lstfield.SelectedValue.ToString Call btngo_Click(sender, e) End Sub
Imports MySql.Data.MySqlClient Public Class Form1 'Represents an SQL statement or stored procedure to execute against a data source. Dim cmd As New MySqlCommand Dim da As New MySqlDataAdapter Public total As Integer Dim publictable As New DataTable 'declare conn as connection and it will now a new connection because 'it is equal to Getconnection Function Dim con As MySqlConnection = jokenconn() Public Function jokenconn() As MySqlConnection Return New MySqlConnection("server=localhost;user id=root;password=;database=") End Function Private Sub btngo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngo.Click Dim publictable As New DataTable Dim sql As String sql = txtquery.Text Try 'bind the connection and query With cmd .Connection = con .CommandText = sql End With 'Gets or sets a Transact-SQL statement or stored procedure used to select records in the data source. da.SelectCommand = cmd da.Fill(publictable) 'get the datasource from publictable and passed to datagridview dtresultview.DataSource = publictable 'dispose the dataadapter da.Dispose() Catch ex As Exception End Try da.Dispose() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sql As String = "SHOW DATABASES" Dim publictable As New DataTable Try 'bind the connection and query With cmd .Connection = con .CommandText = sql End With da.SelectCommand = cmd da.Fill(publictable) With cbdb .DataSource = publictable .DisplayMember = "Database" .ValueMember = "Database" End With da.Dispose() Catch ex As Exception End Try con.Clone() End Sub Private Sub btntest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntest.Click Dim sql As String = "SHOW TABLES FROM " & cbdb.Text Dim publictable As New DataTable Try 'bind the connection and query With cmd .Connection = con .CommandText = Sql End With da.SelectCommand = cmd da.Fill(publictable) ' publictable.Rows.Add("Please Select...") With lstfield .DataSource = publictable .DisplayMember = "Tables_in_" & cbdb.Text .ValueMember = "Tables_in_" & cbdb.Text End With ' dtgrd.Columns(1).Visible = False da.Dispose() Catch ex As Exception End Try con.Clone() End Sub Private Sub lstfield_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstfield.Click txtquery.Text = "SELECT * FROM " & cbdb.Text & "." & lstfield.SelectedValue.ToString Call btngo_Click(sender, e) End Sub End Class