Question DataGridView

murthy285

New member
Joined
Oct 28, 2010
Messages
1
Programming Experience
Beginner
Below is my coding, Actually i want to key in EmployeeID in the textbox and click the view button. Once the button is clicked than the Datagridview table will show information about the employee. However with my coding, All the employees information is displayed. Please help me....thank you

Imports MySql.Data.MySqlClient
Public Class frmView
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost; Database=mysql; User ID=root; Password=12345678;")
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As New DataTable
Dim ds As New DataSet
Dim SQL As String
Dim SearchClass As String
Dim reader As MySqlDataReader



Private Sub frmView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SQL = "SELECT CONCAT(LastName, ', ', FirstName) AS Name, EmployeeID AS ID, City AS City, State AS State, Hand_p AS Handphone, e_mail AS Email, Other_p AS Emergency, Department AS Department FROM userp"
End Sub

Private Sub btnView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView1.Click


If con.State = ConnectionState.Closed Then
con.Open()
End If

If txtView.Text = "" Then
MsgBox("EmployeeID is not entered!", MsgBoxStyle.OkOnly)

Else

Dim ViewCommand As New MySqlCommand("SELECT * FROM userp WHERE EmployeeID = @ID", con)
ViewCommand.Parameters.AddWithValue("@ID", txtView.Text)
Dim SQLReader As MySqlDataReader
SQLReader = ViewCommand.ExecuteReader()


If SQLReader.HasRows Then
SQLReader.Close()
Call procedure(ViewCommand)

Exit Sub
Else
MessageBox.Show("Data was no found!", "Warning!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
SQLReader.Close()
End If
End If




End Sub
Private Sub procedure(ByVal ViewCommand As MySqlCommand)

myData.Clear()
myCommand.Connection = con
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
myAdapter.Fill(myData)
dgvStatus1.DataSource = myData

End Sub



End Class
 

Attachments

  • viewfuck.JPG
    viewfuck.JPG
    170.7 KB · Views: 25
Back
Top