Private Sub btnSelectAsset_Click(sender As Object, e As EventArgs) Handles btnSelectAsset.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString =
"server=localhost;userid=root;password= ;database=myma"
Dim SDA As MySqlDataAdapter
Dim dbDataSet As New DataTable
Dim bSource As New BindingSource
Try
MySqlConn.Open()
COMMAND.Connection = MySqlConn
SDA = New MySqlDataAdapter("select * from myma.user", MySqlConn)
dbDataSet = New DataTable
SDA.Fill(dbDataSet)
DataGridView1.DataSource = dbDataSet
MySqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
object reference not set to an instance of an object.
I got the above error when debugging. Could you please help me correct this.
Try this working example:
Private Sub btnSelectAsset_Click(sender As Object, e As EventArgs) Handles btnSelectAsset.Click
Dim dbConn = New MySqlConnection
Dim dbDataTable = New DataTable
dbConn.ConnectionString = "server=localhost;userid=root;password= ;database=myma"
Try
dbConn.Open()
If (dbConn.State = ConnectionState.Open) Then
Dim dbAdapter = New MySqlDataAdapter("select * from myma.user", dbConn)
dbAdapter.Fill(dbDataTable)
DataGridView1.DataSource = dbDataTable
dbConn.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
dbConn.Dispose()
End Try
End Sub
VB2010Ex & .NET 4 Client Profile.
Related
I am trying to display a value I obatain from a COUNT(*) query in a textbox in vb.net but instead of displaying the obtained value it displays the actual query.
Here is my code:
Imports MySql.Data.MySqlClient
Public Class Statistics
Dim conn As MySqlConnection
Dim command As MySqlCommand
Dim query As String
Dim dadapter As New MySqlDataAdapter
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
conn = New MySqlConnection
conn.ConnectionString =
"server=localhost;userid=root;database=librarydatabase"
Dim reader As MySqlDataReader
Try
conn.Open()
query = "SELECT COUNT(*) FROM login where users='" & Username.Text & "'"
command = New MySqlCommand(query, conn)
reader = command.ExecuteReader
dadapter.SelectCommand = command
If reader.HasRows Then
reader.Read()
takenout.Text = (query)
End If
conn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
conn.Dispose()
End Try
End Sub
Here is a screenshot of my program:
When trying to fix the code I change it to replace takenout.Text = (query) with takenout.Text = (reader.read()) and deleting the reader.read()) above and dadapter.SelectCommand = command
Here is the changed code:
Imports MySql.Data.MySqlClient
Public Class Statistics
Dim conn As MySqlConnection
Dim command As MySqlCommand
Dim query As String
Dim dadapter As New MySqlDataAdapter
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
conn = New MySqlConnection
conn.ConnectionString =
"server=localhost;userid=root;database=librarydatabase"
Dim reader As MySqlDataReader
Try
conn.Open()
query = "SELECT COUNT(*) FROM login where users='" & Username.Text & "'"
command = New MySqlCommand(query, conn)
reader = command.ExecuteReader
If reader.HasRows() Then
takenout.Text = (reader.Read())
End If
conn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
conn.Dispose()
End Try
End Sub
This code doesn't fix the problem but instead displays true in the textbox when the button is pressed no matter whats in the username textbox.
Here is an image of that:
Use command.ExecuteScalar() instead.
Using command.executescalar() fixes the issue.
Here is a copy of the fixed code if anyone else has a similar issue and wants to see a working example.
Public Class Statistics
Dim conn As MySqlConnection
Dim command As MySqlCommand
Dim query As String
Dim dadapter As New MySqlDataAdapter
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
conn = New MySqlConnection
conn.ConnectionString =
"server=localhost;userid=root;database=librarydatabase"
Dim numtakenout As String
Try
conn.Open()
query = "SELECT COUNT(*) FROM login where users='" & Username.Text & "'"
command = New MySqlCommand(query, conn)
numtakenout = Convert.ToString(command.ExecuteScalar())
takenout.Text = numtakenout
conn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
conn.Dispose()
End Try
End Sub
I been searching for code but unfortunatelly I failed, So what better way than asking fellow coder. I dont know how to explain but here what I need. I want to be able to search using textbox associated with radio buttons. I can find anything that is related to STRING ut not integer...
Here is my code
Imports MySql.Data.MySqlClient
Public Class frmGuest
Dim MysqlConn As MySqlConnection
Dim Command As MySqlCommand
Dim dbDataSet As New DataTable
Dim row As DataGridViewRow
Private Sub guestLoad()
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString =
"server=localhost;userid=admin;password=admin;database=gdatabases"
Dim SDA As New MySqlDataAdapter
Dim bsource As New BindingSource
Try
MysqlConn.Open()
Dim Query As String
Query = "select * from gdatabases.guest"
Command = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = Command
SDA.Fill(dbDataSet)
bsource.DataSource = dbDataSet
DataGridView1.DataSource = bsource
SDA.Update(dbDataSet)
MysqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub
Private Sub frmGuest_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
guestLoad()
End Sub
Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
Dim DV As New DataView(dbDataSet)
If rdoReg.Checked Then
DV.RowFilter = String.Format("idguest like = {0}", txtSearch.Text)
DataGridView1.DataSource = DV
ElseIf rdoName.Checked Then
DV.RowFilter = String.Format("Name like '%{0}%'", txtSearch.Text)
DataGridView1.DataSource = DV
ElseIf rdoNRIC.Checked Then
DV.RowFilter = String.Format("Convert(NRIC,'System.String') Like '%{0}%'", txtSearch.Text)
DataGridView1.DataSource = DV
End If
End Sub
Click here for image
Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
Dim DV As New DataView(dbDataSet.Tables(0))
If rdoReg.Checked Then
DV.RowFilter = String.Format("idguest = {0}", txtSearch.Text)
DataGridView1.DataSource = DV
ElseIf rdoName.Checked Then
DV.RowFilter = String.Format("Convert(Name,'System.String') Like '%{0}%'", txtSearch.Text)
DataGridView1.DataSource = DV
ElseIf rdoNRIC.Checked Then
DV.RowFilter = String.Format("Convert(NRIC,'System.String') Like '%{0}%'", txtSearch.Text)
DataGridView1.DataSource = DV
End If
End Sub
I've researched topics about this but unfortunately I can't find anything that I can easily understand. I have a MySQL database entitled GMASS standing for Guidance Monitoring and Scheduling System. What I want to do is when I input the student number from student table, the name of the student will be previewed in my label. How can I do this?I'm basically a beginner in this. Thank you so much in advance.
Imports System
Imports System.Data
Imports MySql.Data.MySqlClient
Public Class bd
Public Shared Mystr As String = MyConnectStr.getConnectString("localhost", "root", "", "databasename")
Public Shared Sub setConnectionString(str As String)
Mystr = str
End Sub
Public Shared Function getConnectionString() As String
Return Mystr
End Function
Public Shared Function Executer_scalar(Query As String) As String
Dim MySqlConn As MySqlConnection = Nothing
Try
MySqlConn = New MySqlConnection(getConnectionString())
Dim MySqlCom As New MySqlCommand(Query, MySqlConn)
MySqlConn.Open()
setNamesUTF8(MySqlConn)
Return MySqlCom.ExecuteScalar().ToString()
Catch ex As Exception
Throw ex
Finally
Try
MySqlConn.Close()
Catch generatedExceptionName As Exception
End Try
End Try
End Function
Public Shared Function Executer_NonQuery(Query As String) As Integer
Dim MySqlConn As MySqlConnection = Nothing
Try
MySqlConn = New MySqlConnection(getConnectionString())
Dim MySqlCom As New MySqlCommand(Query, MySqlConn)
MySqlConn.Open()
setNamesUTF8(MySqlConn)
Return MySqlCom.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
Try
MySqlConn.Close()
Catch ex As Exception
End Try
End Try
End Function
Public Shared Function Query(q As String, Optional table_name As String = "Table") As DataTable
Dim MySqlConn As MySqlConnection = Nothing
Try
MySqlConn = New MySqlConnection(getConnectionString())
Dim MySqlCom As New MySqlCommand(q, MySqlConn)
MySqlConn.Open()
setNamesUTF8(MySqlConn)
Dim MySqlda As New MySqlDataAdapter(MySqlCom)
Dim dt As New DataTable(table_name)
MySqlda.Fill(dt)
Return dt
Catch ex As Exception
Throw ex
Finally
Try
MySqlConn.Close()
Catch ex As Exception
End Try
End Try
End Function
Public Shared Function load_table(table_name As String) As DataTable
Dim MySqlConn As MySqlConnection = Nothing
Try
MySqlConn = New MySqlConnection(getConnectionString())
Dim MySqlCom As New MySqlCommand("SELECT * FROM " & table_name, MySqlConn)
MySqlConn.Open()
setNamesUTF8(MySqlConn)
Dim MySqlda As New MySqlDataAdapter(MySqlCom)
Dim dt As New DataTable(table_name)
MySqlda.Fill(dt)
Return dt
Catch ex As Exception
Throw ex
Finally
Try
MySqlConn.Close()
Catch ex As Exception
End Try
End Try
End Function
Public Shared Function load_tables(ParamArray table_name As String()) As DataSet
Dim MySqlConn As MySqlConnection = Nothing
Try
Dim ds As New DataSet()
Dim MySqlCom As MySqlCommand = Nothing
Dim MySqlda As MySqlDataAdapter = Nothing
Dim dt As DataTable = Nothing
MySqlConn = New MySqlConnection(getConnectionString())
MySqlConn.Open()
setNamesUTF8(MySqlConn)
For i As Integer = 0 To table_name.Length - 1
MySqlCom = New MySqlCommand("SELECT * FROM " & table_name(i), MySqlConn)
MySqlda = New MySqlDataAdapter(MySqlCom)
dt = New DataTable(table_name(i))
MySqlda.Fill(dt)
ds.Tables.Add(dt)
Next
Return ds
Catch ex As Exception
Throw ex
Finally
Try
MySqlConn.Close()
Catch ex As Exception
End Try
End Try
End Function
Public Shared Function load_DataSet(Query As String, Optional table_name As String = "Table") As DataSet
Dim MySqlConn As MySqlConnection = Nothing
Try
MySqlConn = New MySqlConnection(getConnectionString())
Dim MySqlCom As New MySqlCommand(Query, MySqlConn)
MySqlConn.Open()
setNamesUTF8(MySqlConn)
Dim MySqlda As New MySqlDataAdapter(MySqlCom)
Dim ds As New DataSet()
MySqlda.Fill(ds, table_name)
Return ds
Catch ex As Exception
Throw ex
Finally
Try
MySqlConn.Close()
Catch ex As Exception
End Try
End Try
End Function
Public Shared Function load_DataSet_S(ParamArray Query As String()) As DataSet
Dim MySqlConn As MySqlConnection = Nothing
Try
Dim ds As New DataSet()
Dim MySqlCom As MySqlCommand = Nothing
Dim MySqlda As MySqlDataAdapter = Nothing
Dim dt As DataTable = Nothing
MySqlConn = New MySqlConnection(getConnectionString())
MySqlConn.Open()
setNamesUTF8(MySqlConn)
For i As Integer = 0 To Query.Length - 1
MySqlCom = New MySqlCommand(Query(i), MySqlConn)
MySqlda = New MySqlDataAdapter(MySqlCom)
dt = New DataTable("Table_" & i)
MySqlda.Fill(dt)
ds.Tables.Add(dt)
Next
Return ds
Catch ex As Exception
Throw ex
Finally
Try
MySqlConn.Close()
Catch
End Try
End Try
End Function
Public Shared Function load_ps(ps_name As String, Optional params_name As String() = Nothing, Optional params_value As Object() = Nothing) As DataTable
Dim MySqlConn As MySqlConnection = Nothing
Try
MySqlConn = New MySqlConnection(getConnectionString())
Dim MySqlCom As New MySqlCommand(ps_name, MySqlConn)
MySqlCom.CommandType = CommandType.StoredProcedure
If (params_name IsNot Nothing) And (params_value IsNot Nothing) Then
For i As Integer = 0 To params_name.Length - 1
MySqlCom.Parameters.AddWithValue(params_name(i).Replace("#", ""), params_value(i))
Next
End If
MySqlConn.Open()
setNamesUTF8(MySqlConn)
Dim MySqlda As New MySqlDataAdapter(MySqlCom)
Dim dt As New DataTable(ps_name)
MySqlda.Fill(dt)
Return dt
Catch ex As Exception
Throw ex
Finally
Try
MySqlConn.Close()
Catch
End Try
End Try
End Function
Public Shared Function load_ps_ds(ps_name As String, Optional params_name As String() = Nothing, Optional params_value As Object() = Nothing) As DataSet
Dim MySqlConn As MySqlConnection = Nothing
Try
MySqlConn = New MySqlConnection(getConnectionString())
Dim MySqlCom As New MySqlCommand(ps_name, MySqlConn)
MySqlCom.CommandType = CommandType.StoredProcedure
If (params_name IsNot Nothing) And (params_value IsNot Nothing) Then
For i As Integer = 0 To params_name.Length - 1
MySqlCom.Parameters.AddWithValue(params_name(i).Replace("#", ""), params_value(i))
Next
End If
MySqlConn.Open()
setNamesUTF8(MySqlConn)
Dim MySqlda As New MySqlDataAdapter(MySqlCom)
Dim ds As New DataSet()
MySqlda.Fill(ds)
Return ds
Catch ex As Exception
Throw ex
Finally
Try
MySqlConn.Close()
Catch ex As Exception
End Try
End Try
End Function
Public Shared Function load_Reader(Query As String, Optional table_name As String = "Table") As MySqlDataReader
Dim MySqlConn As MySqlConnection = Nothing
Try
MySqlConn = New MySqlConnection(getConnectionString())
Dim MySqlCom As New MySqlCommand(Query, MySqlConn)
MySqlConn.Open()
setNamesUTF8(MySqlConn)
Return MySqlCom.ExecuteReader()
Catch ex As Exception
Throw ex
End Try
End Function
Public Shared Function Execute_Transact(ParamArray Query As String()) As Object
Dim MySqlConn As MySqlConnection = Nothing
Dim tran As MySqlTransaction = Nothing
Try
MySqlConn = New MySqlConnection(getConnectionString())
MySqlConn.Open()
setNamesUTF8(MySqlConn)
tran = MySqlConn.BeginTransaction()
Dim MySqlCom As MySqlCommand() = New MySqlCommand(Query.Length) {}
For i As Integer = 0 To Query.Length - 1
MySqlCom(i) = New MySqlCommand(Query(i), MySqlConn)
MySqlCom(i).Transaction = tran
Next
For i As Integer = 0 To Query.Length - 1
MySqlCom(i).ExecuteNonQuery()
Next
tran.Commit()
Return 0
Catch ex As Exception
Try
tran.Rollback()
Catch exx As Exception
End Try
Throw ex
Finally
Try
MySqlConn.Close()
Catch ex As Exception
End Try
End Try
End Function
Private Shared Sub setNamesUTF8(conn As MySqlConnection)
Try
Dim MySqlCom As New MySqlCommand("SET NAMES 'utf8'", conn)
MySqlCom.ExecuteNonQuery()
Catch ex As Exception
Throw ex
End Try
End Sub
End Class
i was trying to filter datagridview with a use of a combobox that is populated by values from a database
i'm having below error
EvaluateException was unhandled by user code
Cannot find column [year].
here is my code
Imports MySql.Data.MySqlClient
Public Class ReportTeacher
Dim MySqlConnection As MySqlConnection
Dim dbDataSet As New DataTable
Private Sub ReportTeacher_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MySqlConnection = New MySqlConnection
MySqlConnection.ConnectionString = "server = localhost; port=3307; user id = root; password = 1234; database = mcs;"
Dim SDA As New MySqlDataAdapter
Dim bSource As New BindingSource
Try
MySqlConnection.Open()
Dim query As String
query = "SELECT DISTINCT year FROM mcs.year "
Dim da As New MySqlDataAdapter(query, MySqlConnection)
Dim ds As New DataSet
da.Fill(ds, "mcs.year")
With cmbxyear
.DataSource = ds.Tables("mcs.year")
.DisplayMember = "year"
.ValueMember = "year"
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConnection.Dispose()
End Try
Try
MySqlConnection.Open()
Dim query As String
query = "select * from mcs.faculties "
Dim Command As New MySqlCommand(query, MySqlConnection)
SDA.SelectCommand = Command
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
MySqlConnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConnection.Dispose()
End Try
End Sub
Private Sub cmbxyear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbxyear.SelectedIndexChanged
Dim DV As New DataView(dbDataSet)
DV.RowFilter = String.Format(" year like '%{0}%' ", cmbxyear.SelectedItem)
DataGridView1.DataSource = DV
End Sub
can you help me???
it is just the position where you will call the values in mcs. year...it is after when you called the values of mcs.student and insert it into datagrid
I am using MySQL on the back end. My program has two datagridviews, one for the employee table and the other for the employee logs. The problem is whenever I load the data onto the two datagridviews, the data is duplicated. For example there are 4 data on the employee table, it will display the 4 data and then it will display another set of that data just below the first 4. The two datagridviews does that. What seems to be the problem in my code?
Imports MySql.Data.MySqlClient
Public Class ViewMealLog
Dim dbDataSet As New DataTable
Dim dbDataSet2 As New DataTable
Public sConnection As New MySqlConnection
Private Sub load_table()
sConnection = New MySqlConnection
sConnection.ConnectionString = "server=localhost;userid=root;password=;database=cph;Convert Zero Datetime=True"
Dim SDA As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim bSource As New BindingSource
Try
sConnection.Open()
Dim Query As String
Query = "select * from swipe_table"
sqlCommand = New MySqlCommand(Query, sConnection)
SDA.SelectCommand = sqlCommand
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
sConnection.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
sConnection.Dispose()
End Try
End Sub
Private Sub load_table2()
sConnection = New MySqlConnection
sConnection.ConnectionString = "server=localhost;userid=root;password=;database=cph;Convert Zero Datetime=True"
Dim SDAX As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim bSource As New BindingSource
Try
sConnection.Open()
Dim Query As String
Query = "select emp_no, emp_firstnm, emp_midnm, emp_lastnm, schedtype from employee_table"
sqlCommand = New MySqlCommand(Query, sConnection)
SDAX.SelectCommand = sqlCommand
SDAX.Fill(dbDataSet2)
bSource.DataSource = dbDataSet2
DataGridView2.DataSource = bSource
SDAX.Update(dbDataSet2)
sConnection.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
sConnection.Dispose()
End Try
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
load_table2()
sConnection = New MySqlConnection
sConnection.ConnectionString = "server=localhost;userid=root;password=;database=cph;Convert Zero Datetime=True"
Dim SDAX As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim bSource As New BindingSource
Try
sConnection.Open()
Dim Query As String
Query = "select emp_no, emp_firstnm, emp_midnm, emp_lastnm, schedtype from employee_table"
sqlCommand = New MySqlCommand(Query, sConnection)
SDAX.SelectCommand = sqlCommand
SDAX.Fill(dbDataSet2)
bSource.DataSource = dbDataSet2
DataGridView2.DataSource = bSource
SDAX.Update(dbDataSet2)
sConnection.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
sConnection.Dispose()
End Try
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
load_table()
sConnection = New MySqlConnection
sConnection.ConnectionString = "server=localhost;userid=root;password=;database=cph;Convert Zero Datetime=True"
Dim SDA As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim bSource As New BindingSource
Try
sConnection.Open()
Dim Query As String
Query = "select * from swipe_table"
sqlCommand = New MySqlCommand(Query, sConnection)
SDA.SelectCommand = sqlCommand
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
sConnection.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
sConnection.Dispose()
End Try
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
MainMenu.Show()
Me.Hide()
End Sub
Private Sub txtSearch_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtSearch.TextChanged
Dim DV As New DataView(dbDataSet)
DV.RowFilter = "CONVERT(emp_no, System.String) LIKE '%" & txtSearch.Text & "%' "
DataGridView1.DataSource = DV
End Sub
Private Sub txtSearch2_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtSearch2.TextChanged
Dim DV As New DataView(dbDataSet)
DV.RowFilter = "CONVERT(log_date, System.String) LIKE '%" & txtSearch2.Text & "%' "
DataGridView1.DataSource = DV
End Sub
Private Sub txtSearch3_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtSearch3.TextChanged
Dim DV As New DataView(dbDataSet2)
DV.RowFilter = "CONVERT(emp_no, System.String) LIKE '%" & txtSearch3.Text & "%' "
DataGridView2.DataSource = DV
End Sub
Private Sub txtSearch4_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtSearch4.TextChanged
Dim DV As New DataView(dbDataSet2)
DV.RowFilter = "CONVERT(emp_lastnm, System.String) LIKE '%" & txtSearch4.Text & "%' "
DataGridView2.DataSource = DV
End Sub
End Class
Why would you call the load_table and load_table2 function in your button click event? try removing the function call as your button click event already query the database.
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
"'load_table2()<<-----"
sConnection = New MySqlConnection
sConnection.ConnectionString = "server=localhost;userid=root;password=;database=cph;Convert Zero Datetime=True"
Dim SDAX As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim bSource As New BindingSource
Try
sConnection.Open()
Dim Query As String
Query = "select emp_no, emp_firstnm, emp_midnm, emp_lastnm, schedtype from employee_table"
sqlCommand = New MySqlCommand(Query, sConnection)
SDAX.SelectCommand = sqlCommand
SDAX.Fill(dbDataSet2)
bSource.DataSource = dbDataSet2
DataGridView2.DataSource = bSource
SDAX.Update(dbDataSet2)
sConnection.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
sConnection.Dispose()
End Try
End Sub
UPDATE
OR like this
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
load_table2()
End Sub