Search integer value using radiobutton - mysql

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

Related

Inserting images in mysql database with a longblob data type

Somebody check my code for inserting image into the database.I know there's some error but can't figure it out.When i run the code it worked but when i click the done button it always says NullReferenceException Here's What I've got
Imports MySql.Data.MySqlClient
Imports System.IO
Public Class adminreg
Dim con As MySqlConnection
Dim cmd As MySqlCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim reader As MySqlDataReader
Dim mstream As New System.IO.MemoryStream
PictureBox1.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim arrImage() As Byte = mstream.GetBuffer()
mstream.Close()
con = New MySqlConnection
con.ConnectionString = "server=localhost;userid=root;password=1234;database=dat"
Try
con.Open()
Dim query As String
query = "insert into dat.login (idlogin,user,password,name,position,ownpic) values ('" & id.Text & "','" & usertxt.Text & "','" & passtxt.Text & "','" & nmetxt.Text & "','" & postxt.Text & "',#ownpic)"
cmd.Parameters.AddWithValue("#ownpic", arrImage)
cmd = New MySqlCommand(query, con)
reader = cmd.ExecuteReader
MessageBox.Show("Data Saved")
con.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
con.Dispose()
End Try
End Sub
Private Sub adminreg_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
OpenFileDialog1.Filter = "imahe lang (*.jpg, *.bmp, *.png) | *.jpg; *.bmp; *.png| all files (*.*) | *.*"
If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Login.Show()
Me.Hide()
End Sub
End Class
Any Suggestion is highly appreciated Thank you...Just a beginner in VB.net
Private Sub pbStudentImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbStudentImage.Click, txtStudentImage.Enter, txtStudentImage.Click
Try
Dim fileOpener As OpenFileDialog = New OpenFileDialog()
fileOpener.Filter = "Image files | *.jpg"
If fileOpener.ShowDialog() = Windows.Forms.DialogResult.OK Then
pbStudentImage.Image = Image.FromFile(fileOpener.FileName)
txtStudentImage.Text = fileOpener.FileName
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub btnSaveImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveImage.Click
Dim con As MySqlConnection = New MySqlConnection(ConString)
Dim cmd As MySqlCommand
Dim fs As FileStream
Dim br As BinaryReader
Try
If txtFirstName.Text.Length > 0 And txtStudentImage.Text.Length > 0 Then
Dim FileName As String = txtStudentImage.Text
Dim ImageData() As Byte
fs = New FileStream(FileName, FileMode.Open, FileAccess.Read)
br = New BinaryReader(fs)
ImageData = br.ReadBytes(CType(fs.Length, Integer))
br.Close()
fs.Close()
Dim CmdString As String = "INSERT INTO Students(FirstName, LastName, Image, Address) VALUES(#FirstName, #LastName, #Image, #Address)"
cmd = New MySqlCommand(CmdString, con)
cmd.Parameters.Add("#FirstName", MySqlDbType.VarChar, 45)
cmd.Parameters.Add("#LastName", MySqlDbType.VarChar, 45)
cmd.Parameters.Add(";#Image", MySqlDbType.Blob)
cmd.Parameters.Add("#Address", MySqlDbType.VarChar, 100)
cmd.Parameters("#FirstName").Value = txtFirstName.Text
cmd.Parameters("#LastName").Value = txtLastName.Text
cmd.Parameters("#Image").Value = ImageData
cmd.Parameters("#Address").Value = txtAddress.Text
con.Open()
Dim RowsAffected As Integer = cmd.ExecuteNonQuery()
If (RowsAffected > 0) Then
MsgBox("Image saved successfully!")
End If
con.Close()
Else
MsgBox("Incomplete data!", MsgBoxStyle.Critical, "")
End If
Catch ex As Exception
MsgBox(ex.ToString())
Finally
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
Private Sub pbStudentImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbStudentImage.Click, txtStudentImage.Enter, txtStudentImage.Click
Try
Dim fileOpener As OpenFileDialog = New OpenFileDialog()
fileOpener.Filter = "Image files | *.jpg"
If fileOpener.ShowDialog() = Windows.Forms.DialogResult.OK Then
pbStudentImage.Image = Image.FromFile(fileOpener.FileName)
txtStudentImage.Text = fileOpener.FileName
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub pbStudentImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbStudentImage.Click, txtStudentImage.Enter, txtStudentImage.Click
Try
Dim fileOpener As OpenFileDialog = New OpenFileDialog()
fileOpener.Filter = "Image files | *.jpg"
If fileOpener.ShowDialog() = Windows.Forms.DialogResult.OK Then
pbStudentImage.Image = Image.FromFile(fileOpener.FileName)
txtStudentImage.Text = fileOpener.FileName
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub btnSaveImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveImage.Click
Dim con As MySqlConnection = New MySqlConnection(ConString)
Dim cmd As MySqlCommand
Dim fs As FileStream
Dim br As BinaryReader

object reference not set to an instance of an object

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.

Search bar not working; column not found?

Ok. I am making a BIG program that should be released today but sadly i delayed because of this problem while testing. I have administration area to recover people informatio just in case and i noticed search bar dosen't work giving me a error that column is not working. I am using database MySql. Programming in vb.net. The error is: Cannot find column [nusername]. But it does exist. Everything works correctly. And yes i know about the sql injection ignore it. Here is my code but please don't steal my coding:
Imports MySql.Data.MySqlClient
Public Class DeathLairAdminControlPanel
Dim MySqlConn As MySqlConnection
Dim MySqlCmd As MySqlCommand
Dim dbDT As New DataTable
Public Property AUsernameHomePass As String
Private Sub DeathLairAdminControlPanel_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LabelALoggedIn.Text = AUsernameHomePass
End Sub
Private Sub ButtonUpdateU_Click(sender As Object, e As EventArgs) Handles ButtonUpdateU.Click
If TextBoxNUsern.Text = "" Or TextBoxNEmail.Text = "" Or TextBoxNPass.Text = "" Or TextBoxNPhone.Text = "" Then
MessageBox.Show("Please don't leave empty areas.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf TextBoxNUsern.Text.Length < 4 Then
MessageBox.Show("Username too short.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf TextBoxNEmail.Text.Length < 8 Then
MessageBox.Show("Email cant be that short. IT MUST BE VALID!.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf TextBoxNPass.Text.Length < 6 Then
MessageBox.Show("Password can't be that short. Make it longer and secure.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf TextBoxNPhone.Text.Length < 6 Then
MessageBox.Show("Phone number can't be that short. IT MUST BE VALID.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf System.Text.RegularExpressions.Regex.IsMatch(TextBoxNUsern.Text, "^[A-Za-z0-9]+$") And System.Text.RegularExpressions.Regex.IsMatch(TextBoxNPass.Text, "^[A-Za-z0-9.]+$") And System.Text.RegularExpressions.Regex.IsMatch(TextBoxNEmail.Text, "\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*") And System.Text.RegularExpressions.Regex.IsMatch(TextBoxNPhone.Text, "^\+[0-9()-+ ]+$") And System.Text.RegularExpressions.Regex.IsMatch(TextBoxNCity.Text, "^[A-Za-z ]+$") Then
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString =
"server=localhost;userid=root;password=HIDDEN;database=syscore"
Dim MySqlRea As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "update syscore.normaluser set nusername='" & TextBoxNUsern.Text & "',nemail='" & TextBoxNEmail.Text & "',npass='" & TextBoxNPass.Text & "',nphone='" & TextBoxNPhone.Text & "',ncity='" & TextBoxNCity.Text & "' where nusername='" & TextBoxNUsern.Text & "'"
MySqlCmd = New MySqlCommand(Query, MySqlConn)
MySqlRea = MySqlCmd.ExecuteReader
MessageBox.Show("User has been updated.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
MySqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End If
loaddatabase_table()
End Sub
Private Sub ButtonDeleteU_Click(sender As Object, e As EventArgs) Handles ButtonDeleteU.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString =
"server=localhost;userid=root;password=HIDDEN;database=syscore"
Dim MySqlRea As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "delete from syscore.normaluser where nusername'" & TextBoxNUsern.Text & "'"
MySqlCmd = New MySqlCommand(Query, MySqlConn)
MySqlRea = MySqlCmd.ExecuteReader
MessageBox.Show("User has been deleted.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
TextBoxNUsern.Text = ""
TextBoxNEmail.Text = ""
TextBoxNPass.Text = ""
TextBoxNPhone.Text = ""
TextBoxNCity.Text = ""
MySqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
loaddatabase_table()
End Sub
Private Sub loaddatabase_table()
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString =
"server=localhost;userid=root;password=HIDDEN;database=syscore"
Dim MySqlDAd As New MySqlDataAdapter
Dim dbDataSet As New DataTable
Dim bSource As New BindingSource
Try
MySqlConn.Open()
Dim Query As String
Query = "select * from syscore.normaluser"
MySqlCmd = New MySqlCommand(Query, MySqlConn)
MySqlDAd.SelectCommand = MySqlCmd
MySqlDAd.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
MySqlDAd.Update(dbDataSet)
TextBoxNUsern.Text = ""
TextBoxNEmail.Text = ""
TextBoxNPass.Text = ""
TextBoxNPhone.Text = ""
TextBoxNCity.Text = ""
MySqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
Private Sub ButtonLDB_Click(sender As Object, e As EventArgs) Handles ButtonLDB.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString =
"server=localhost;userid=root;password=HIDDEN;database=syscore"
Dim MySqlDAd As New MySqlDataAdapter
Dim dbDataSet As New DataTable
Dim bSource As New BindingSource
Try
MySqlConn.Open()
Dim Query As String
Query = "select * from syscore.normaluser"
MySqlCmd = New MySqlCommand(Query, MySqlConn)
MySqlDAd.SelectCommand = MySqlCmd
MySqlDAd.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
MySqlDAd.Update(dbDataSet)
TextBoxNUsern.Text = ""
TextBoxNEmail.Text = ""
TextBoxNPass.Text = ""
TextBoxNPhone.Text = ""
TextBoxNCity.Text = ""
MySqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
loaddatabase_table()
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.RowIndex >= 0 Then
Dim gridrow As DataGridViewRow
gridrow = Me.DataGridView1.Rows(e.RowIndex)
TextBoxNUsern.Text = gridrow.Cells("nusername").Value.ToString
TextBoxNEmail.Text = gridrow.Cells("nemail").Value.ToString
TextBoxNPass.Text = gridrow.Cells("npass").Value.ToString
TextBoxNPhone.Text = gridrow.Cells("nphone").Value.ToString
TextBoxNCity.Text = gridrow.Cells("ncity").Value.ToString
End If
End Sub
Private Sub TextBoxSdbgrid_TextChanged(sender As Object, e As EventArgs) Handles TextBoxSdbgrid.TextChanged
Dim DV As New DataView(dbDT)
' ERROR HERE:
DV.RowFilter = String.Format("nusername Like '%{0}%'", TextBoxSdbgrid.Text)
DataGridView1.DataSource = DV
End Sub
Private Sub ReportToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ReportToolStripMenuItem.Click
MessageBox.Show("To get support or report do it on skype gangsteris33 we are always online until night.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub LoginToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoginToolStripMenuItem.Click
Form1.Show()
TextBoxNCity.Text = ""
TextBoxNEmail.Text = ""
TextBoxNPass.Text = ""
TextBoxNPhone.Text = ""
TextBoxNUsern.Text = ""
TextBoxSdbgrid.Text = ""
Me.Hide()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub ButtonClearChat_Click(sender As Object, e As EventArgs) Handles ButtonClearChat.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString =
"server=localhost;userid=root;password=HIDDEN;database=sysinfo"
Dim MySqlRea As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "delete from syscore.normaluser"
MySqlCmd = New MySqlCommand(Query, MySqlConn)
MySqlRea = MySqlCmd.ExecuteReader
MessageBox.Show("Chat has been cleaned.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
MySqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
End Class
I hope you can fix it. I been trying to find the reason but no idea. Someone who can edit this please fix this bad code pasting. (website problem not my skill). If someone want to mark this as duplicate then please give me a fix using my code before you block this topic.
Inside the method loaddatabase_table add this line after the dataset fill
Private Sub loaddatabase_table()
Dim dbDataSet As New DataTable ' This is a misleading name.
....
MySqlDAd.Fill(dbDataSet)
' Add this line
dbDT = dbDataSet
End Sub
Now the global variable dbDT points to the effective table loaded from the db, so, when you build the DataView the column nusername is present in the source datatable
Note that the code in the delete button cannot work because you are missing the = between the nusername and the value to delete
Finally, while calling ExecuteReader works also for INSERT/UPDATE/DELETE query, the correct method to use is ExecuteNonQuery to avoid the unnecessary building of a DataReader when you have nothing to read from your command
you should check your connection string or put an error message like this:
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

EvaluateException was unhandled by user code Cannot find column [year]

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

How to fix double output on DataGridView on VB.Net

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