Solved

Search button

Posted on 2016-09-23
7
22 Views
Last Modified: 2016-10-26
This is my code can you help me with the code for the search button

Public Class frmTrainer

    Dim Mode As String
    Dim path As String = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\mandlak\Desktop\Swazi Nkosi\CPISAT9910280197089.accdb"

    Private Function GetNextTrainerNo()
        Dim TrainerNo As Integer


        Try
            Dim connection As New OleDb.OleDbConnection
            Dim command As New OleDb.OleDbCommand
            Dim table As New Data.DataTable


            connection.ConnectionString = path
            connection.Open()


            command.Connection = connection
            command.CommandText = "SELECT TOP 1 Trainer_No FROM Trainer ORDER BY Trainer_No DESC"


            table.Load(command.ExecuteReader())
            connection.Close()

            If table.Rows.Count > 0 Then
                If Integer.TryParse(table(0)("Trainer_No").ToString(), TrainerNo) Then

                    TrainerNo = TrainerNo + 1

                End If
            Else
                TrainerNo = 221
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString)

        End Try

        Return TrainerNo

    End Function
    Private Function GetScaleID()
        Dim ScaleID As Integer


        Try
            Dim connection As New OleDb.OleDbConnection
            Dim command As New OleDb.OleDbCommand
            Dim table As New Data.DataTable


            connection.ConnectionString = path
            connection.Open()


            command.Connection = connection
            command.CommandText = "SELECT TOP 1 Scale_ID FROM Trainer ORDER BY Trainer_No DESC"


            table.Load(command.ExecuteReader())
            connection.Close()

            If table.Rows.Count > 0 Then
                If Integer.TryParse(table(0)("Scale_ID").ToString(), ScaleID) Then



                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString)

        End Try

        Return ScaleID

    End Function

    Private Function GetMonthlySalary()

        Dim MonthlySalary As Integer


        Try
            Dim connection As New OleDb.OleDbConnection
            Dim command As New OleDb.OleDbCommand
            Dim table As New Data.DataTable


            connection.ConnectionString = path
            connection.Open()


            command.Connection = connection
            command.CommandText = "SELECT Monthly_Salary FROM Trainer ORDER BY Trainer_ID DESC"


            table.Load(command.ExecuteReader())
            connection.Close()

            If table.Rows.Count > 0 Then
                If Integer.TryParse(table(0)("Monthly_Salary").ToString(), MonthlySalary) Then


                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString)

        End Try

        Return MonthlySalary

    End Function

    Private Sub GetTrainers()
        txtID.Text = ""
        txtName.Text = ""
        txtSurnamr.Text = ""
        txtContactNo.Text = ""
        txtClassType.Text = ""
        txtmonthlysalary.Text = ""
        txtScaleID.Text = ""
        txtTrainerNo.Text = ""

        Try
            Dim connection As New OleDb.OleDbConnection
            Dim command As New OleDb.OleDbCommand
            Dim table As New Data.DataTable


            connection.ConnectionString = path
            connection.Open()


            command.Connection = connection
            command.CommandText = "SELECT* FROM Trainer ORDER BY Trainer_No"

            table.Load(command.ExecuteReader())
            connection.Close()

            grvTrainer.DataSource = table

        Catch ex As Exception
            MessageBox.Show(ex.ToString)

        End Try

    End Sub

    Private Sub GetTrainer(ByVal pID As Integer)

        Try
            Dim connection As New OleDb.OleDbConnection
            Dim command As New OleDb.OleDbCommand
            Dim table As New Data.DataTable


            connection.ConnectionString = path
            connection.Open()


            command.Connection = connection
            command.CommandText = "SELECT* FROM Trainer WHERE ID=@ID"

            Dim parID = New OleDb.OleDbParameter("@ID", pID)
            command.Parameters.Add(parID)

            table.Load(command.ExecuteReader())
            connection.Close()


            If table.Rows.Count > 0 Then

                txtID.Text = table(0)("ID").ToString
                txtName.Text = table(0)("Trainer_Name").ToString
                txtSurnamr.Text = table(0)("Trainer_Surname").ToString
                txtContactNo.Text = table(0)("Contact_No").ToString
                txtClassType.Text = table(0)("Class_Type").ToString
                txtmonthlysalary.Text = table(0)("Monthly_Salary").ToString
                txtScaleID.Text = table(0)("Scale_ID").ToString
                txtTrainerNo.Text = table(0)("Trainer_No").ToString
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        grvTrainer.Enabled = False

        btnAdd.Enabled = False
        btnUpdate.Enabled = False
        btnDelete.Enabled = False

        'Enabling for the Add event
        btnSubmit.Enabled = True
        btnCancel.Enabled = True

        Mode = "INSERT"

        txtID.Text = ""
        txtName.Text = ""
        txtSurnamr.Text = ""
        txtContactNo.Text = ""
        txtClassType.Text = ""


        txtmonthlysalary.Text = GetMonthlySalary().ToString
        txtScaleID.Text = GetScaleID().ToString
        txtTrainerNo.Text = GetNextTrainerNo().ToString()


    End Sub

    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        If grvTrainer.Rows.Count > 0 Then

            If MessageBox.Show("Want to delete?", "Confirm delete?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then

                Try
                    Dim connection As New OleDb.OleDbConnection
                    Dim command As New OleDb.OleDbCommand


                    connection.ConnectionString = path
                    connection.Open()

                    command.Connection = connection
                    command.CommandText = "DELETE FROM Trainer WHERE ID = @ID"


                    Dim parID = New OleDb.OleDbParameter("@ID", grvTrainer.CurrentRow.Cells("ID").Value)
                    command.Parameters.Add(parID)
                    command.ExecuteNonQuery()
                    connection.Close()
                    GetTrainers()

                Catch ex As Exception
                    MessageBox.Show(ex.ToString)
                End Try
            End If
        Else
            MessageBox.Show("There are no records to delete......")
        End If
    End Sub

    Private Sub frmTrainer_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        GetTrainers()
        btnSubmit.Enabled = False
        btnCancel.Enabled = False
        Mode = ""

    End Sub

    Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click

        If String.IsNullOrEmpty(txtName.Text) Then
            MessageBox.Show("Please enter a name")
            Return
        End If

        If String.IsNullOrEmpty(txtSurnamr.Text) Then
            MessageBox.Show("Please enter a surname")
            Return
        End If

        If String.IsNullOrEmpty(txtContactNo.Text) Then
            MessageBox.Show("Please enter the contact no")
            Return
        End If

        If String.IsNullOrEmpty(txtClassType.Text) Then
            MessageBox.Show("Please enter the class type")
            Return
        End If

        Select Case Mode

            Case "INSERT"

                Try
                    Dim connection As New OleDb.OleDbConnection
                    Dim command As New OleDb.OleDbCommand

                    connection.ConnectionString = path
                    connection.Open()


                    command.Connection = connection
                    command.CommandText = "INSERT INTO Trainer (Trainer_Name, Trainer_Surname,Contact_No,Class_Type,Monthly_Salary,Scale_ID,Trainer_No)VALUES(@Name, @Surname, @ContactNo, @ClassType, @MonthlySalary,ScaleID, @TrainerNo)"

                    Dim parName = New OleDb.OleDbParameter("@Name", txtName.Text)
                    Dim parSurname = New OleDb.OleDbParameter("@Surname", txtSurnamr.Text)
                    Dim parContactNo = New OleDb.OleDbParameter("@ContactNo", txtContactNo.Text)
                    Dim parClassType = New OleDb.OleDbParameter("@ClassType", txtClassType.Text)
                    Dim parMonthlySalary = New OleDb.OleDbParameter("@MonthlySalary", txtmonthlysalary.Text)
                    Dim parScaleID = New OleDb.OleDbParameter("@ScaleID", txtScaleID.Text)
                    Dim parTrainerNo = New OleDb.OleDbParameter("@TrainerNo", txtTrainerNo.Text)


                    command.Parameters.Add(parName)
                    command.Parameters.Add(parSurname)
                    command.Parameters.Add(parContactNo)
                    command.Parameters.Add(parClassType)
                    command.Parameters.Add(parMonthlySalary)
                    command.Parameters.Add(parScaleID)
                    command.Parameters.Add(parTrainerNo)

                    command.ExecuteNonQuery()
                    connection.Close()
                    GetTrainers()

                Catch ex As Exception
                    MessageBox.Show(ex.ToString)
                End Try



            Case "UPDATE"

                Try
                    Dim connection As New OleDb.OleDbConnection
                    Dim command As New OleDb.OleDbCommand


                    connection.ConnectionString = path
                    connection.Open()

                    command.Connection = connection
                    command.CommandText = "UPDATE Trainer SET Trainer_Name=@Name, Trainer_Surname=@Surname, Contact_No=@ContactNo, Class_Type=@ClassType WHERE ID = @ID"


                    Dim parName = New OleDb.OleDbParameter("@Name", txtName.Text)
                    Dim parSurname = New OleDb.OleDbParameter("@Surname", txtSurnamr.Text)
                    Dim parID = New OleDb.OleDbParameter("@ID", txtID.Text)
                    Dim parContactNo = New OleDb.OleDbParameter("@ContactNo", txtContactNo.Text)
                    Dim parClassType = New OleDb.OleDbParameter("@ClassType", txtClassType.Text)



                    'Adding Parameters to the command object
                    command.Parameters.Add(ParName)
                    command.Parameters.Add(parSurname)
                    command.Parameters.Add(parID)
                    command.Parameters.Add(parContactNo)
                    command.Parameters.Add(parClassType)


                    'Executing Parameters
                    command.ExecuteNonQuery()
                    connection.Close()
                    GetTrainers()

                Catch ex As Exception
                    MessageBox.Show(ex.ToString())

                End Try

            Case Else
                MessageBox.Show("Nothing to Submit")

        End Select

        Mode = ""
        grvTrainer.Enabled = True
        btnSubmit.Enabled = False
        btnCancel.Enabled = False

        btnAdd.Enabled = True
        btnDelete.Enabled = True
        btnUpdate.Enabled = True

    End Sub

    Private Sub grvTrainer_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles grvTrainer.CellContentClick

        Dim ID As Integer

        If Integer.TryParse(grvTrainer.CurrentRow.Cells("ID").Value.ToString(), ID) Then
            GetTrainer(ID)
        End If

    End Sub

    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click

        grvTrainer.Enabled = True
        btnSubmit.Enabled = False
        btnCancel.Enabled = False

        btnAdd.Enabled = True
        btnDelete.Enabled = True
        btnUpdate.Enabled = True
        Mode = ""

        If grvTrainer.Rows.Count > 0 Then
            Dim ID As Integer

            If Integer.TryParse(grvTrainer.CurrentRow.Cells("ID").Value.ToString(), ID) Then
                GetTrainer(ID)
            End If

            txtID.Text = ""
            txtName.Text = ""
            txtSurnamr.Text = ""
            txtContactNo.Text = ""
            txtClassType.Text = ""
            txtmonthlysalary.Text = ""
            txtScaleID.Text = ""
            txtTrainerNo.Text = ""
        End If

    End Sub

    Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click

        btnAdd.Enabled = False
        btnDelete.Enabled = False
        btnUpdate.Enabled = False

        btnSubmit.Enabled = True
        btnCancel.Enabled = True

        Mode = "UPDATE"

    End Sub

    Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Application.Exit()
    End Sub

   
End Class
0
Comment
Question by:Swazi Nkosi
  • 4
  • 3
7 Comments
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41812186
Public Class frmTrainer

    Dim Mode As String
    Dim path As String = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\mandlak\Desktop\Swazi Nkosi\CPISAT9910280197089.accdb"

    Private Function GetNextTrainerNo()
        Dim TrainerNo As Integer


        Try
            Dim connection As New OleDb.OleDbConnection
            Dim command As New OleDb.OleDbCommand
            Dim table As New Data.DataTable


            connection.ConnectionString = path
            connection.Open()


            command.Connection = connection
            command.CommandText = "SELECT TOP 1 Trainer_No FROM Trainer ORDER BY Trainer_No DESC"


            table.Load(command.ExecuteReader())
            connection.Close()

            If table.Rows.Count > 0 Then
                If Integer.TryParse(table(0)("Trainer_No").ToString(), TrainerNo) Then

                    TrainerNo = TrainerNo + 1

                End If
            Else
                TrainerNo = 221
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString)

        End Try

        Return TrainerNo

    End Function
    Private Function GetScaleID()
        Dim ScaleID As Integer


        Try
            Dim connection As New OleDb.OleDbConnection
            Dim command As New OleDb.OleDbCommand
            Dim table As New Data.DataTable


            connection.ConnectionString = path
            connection.Open()


            command.Connection = connection
            command.CommandText = "SELECT TOP 1 Scale_ID FROM Trainer ORDER BY Trainer_No DESC"


            table.Load(command.ExecuteReader())
            connection.Close()

            If table.Rows.Count > 0 Then
                If Integer.TryParse(table(0)("Scale_ID").ToString(), ScaleID) Then



                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString)

        End Try

        Return ScaleID

    End Function

    Private Function GetMonthlySalary()

        Dim MonthlySalary As Integer


        Try
            Dim connection As New OleDb.OleDbConnection
            Dim command As New OleDb.OleDbCommand
            Dim table As New Data.DataTable


            connection.ConnectionString = path
            connection.Open()


            command.Connection = connection
            command.CommandText = "SELECT Monthly_Salary FROM Trainer ORDER BY Trainer_ID DESC"


            table.Load(command.ExecuteReader())
            connection.Close()

            If table.Rows.Count > 0 Then
                If Integer.TryParse(table(0)("Monthly_Salary").ToString(), MonthlySalary) Then


                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString)

        End Try

        Return MonthlySalary

    End Function

    Private Sub GetTrainers()
        txtID.Text = ""
        txtName.Text = ""
        txtSurnamr.Text = ""
        txtContactNo.Text = ""
        txtClassType.Text = ""
        txtmonthlysalary.Text = ""
        txtScaleID.Text = ""
        txtTrainerNo.Text = ""

        Try
            Dim connection As New OleDb.OleDbConnection
            Dim command As New OleDb.OleDbCommand
            Dim table As New Data.DataTable


            connection.ConnectionString = path
            connection.Open()


            command.Connection = connection
            command.CommandText = "SELECT* FROM Trainer ORDER BY Trainer_No"

            table.Load(command.ExecuteReader())
            connection.Close()

            grvTrainer.DataSource = table

        Catch ex As Exception
            MessageBox.Show(ex.ToString)

        End Try

    End Sub

    Private Sub GetTrainer(ByVal pID As Integer)

        Try
            Dim connection As New OleDb.OleDbConnection
            Dim command As New OleDb.OleDbCommand
            Dim table As New Data.DataTable


            connection.ConnectionString = path
            connection.Open()


            command.Connection = connection
            command.CommandText = "SELECT* FROM Trainer WHERE ID=@ID"

            Dim parID = New OleDb.OleDbParameter("@ID", pID)
            command.Parameters.Add(parID)

            table.Load(command.ExecuteReader())
            connection.Close()


            If table.Rows.Count > 0 Then

                txtID.Text = table(0)("ID").ToString
                txtName.Text = table(0)("Trainer_Name").ToString
                txtSurnamr.Text = table(0)("Trainer_Surname").ToString
                txtContactNo.Text = table(0)("Contact_No").ToString
                txtClassType.Text = table(0)("Class_Type").ToString
                txtmonthlysalary.Text = table(0)("Monthly_Salary").ToString
                txtScaleID.Text = table(0)("Scale_ID").ToString
                txtTrainerNo.Text = table(0)("Trainer_No").ToString
            End If

        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        grvTrainer.Enabled = False

        btnAdd.Enabled = False
        btnUpdate.Enabled = False
        btnDelete.Enabled = False

        'Enabling for the Add event
        btnSubmit.Enabled = True
        btnCancel.Enabled = True

        Mode = "INSERT"

        txtID.Text = ""
        txtName.Text = ""
        txtSurnamr.Text = ""
        txtContactNo.Text = ""
        txtClassType.Text = ""


        txtmonthlysalary.Text = GetMonthlySalary().ToString
        txtScaleID.Text = GetScaleID().ToString
        txtTrainerNo.Text = GetNextTrainerNo().ToString()


    End Sub

    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        If grvTrainer.Rows.Count > 0 Then

            If MessageBox.Show("Want to delete?", "Confirm delete?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then

                Try
                    Dim connection As New OleDb.OleDbConnection
                    Dim command As New OleDb.OleDbCommand


                    connection.ConnectionString = path
                    connection.Open()

                    command.Connection = connection
                    command.CommandText = "DELETE FROM Trainer WHERE ID = @ID"


                    Dim parID = New OleDb.OleDbParameter("@ID", grvTrainer.CurrentRow.Cells("ID").Value)
                    command.Parameters.Add(parID)
                    command.ExecuteNonQuery()
                    connection.Close()
                    GetTrainers()

                Catch ex As Exception
                    MessageBox.Show(ex.ToString)
                End Try
            End If
        Else
            MessageBox.Show("There are no records to delete......")
        End If
    End Sub

    Private Sub frmTrainer_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        GetTrainers()
        btnSubmit.Enabled = False
        btnCancel.Enabled = False
        Mode = ""

    End Sub

    Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click

        If String.IsNullOrEmpty(txtName.Text) Then
            MessageBox.Show("Please enter a name")
            Return
        End If

        If String.IsNullOrEmpty(txtSurnamr.Text) Then
            MessageBox.Show("Please enter a surname")
            Return
        End If

        If String.IsNullOrEmpty(txtContactNo.Text) Then
            MessageBox.Show("Please enter the contact no")
            Return
        End If

        If String.IsNullOrEmpty(txtClassType.Text) Then
            MessageBox.Show("Please enter the class type")
            Return
        End If

        Select Case Mode

            Case "INSERT"

                Try
                    Dim connection As New OleDb.OleDbConnection
                    Dim command As New OleDb.OleDbCommand

                    connection.ConnectionString = path
                    connection.Open()


                    command.Connection = connection
                    command.CommandText = "INSERT INTO Trainer (Trainer_Name, Trainer_Surname,Contact_No,Class_Type,Monthly_Salary,Scale_ID,Trainer_No)VALUES(@Name, @Surname, @ContactNo, @ClassType, @MonthlySalary,ScaleID, @TrainerNo)"

                    Dim parName = New OleDb.OleDbParameter("@Name", txtName.Text)
                    Dim parSurname = New OleDb.OleDbParameter("@Surname", txtSurnamr.Text)
                    Dim parContactNo = New OleDb.OleDbParameter("@ContactNo", txtContactNo.Text)
                    Dim parClassType = New OleDb.OleDbParameter("@ClassType", txtClassType.Text)
                    Dim parMonthlySalary = New OleDb.OleDbParameter("@MonthlySalary", txtmonthlysalary.Text)
                    Dim parScaleID = New OleDb.OleDbParameter("@ScaleID", txtScaleID.Text)
                    Dim parTrainerNo = New OleDb.OleDbParameter("@TrainerNo", txtTrainerNo.Text)


                    command.Parameters.Add(parName)
                    command.Parameters.Add(parSurname)
                    command.Parameters.Add(parContactNo)
                    command.Parameters.Add(parClassType)
                    command.Parameters.Add(parMonthlySalary)
                    command.Parameters.Add(parScaleID)
                    command.Parameters.Add(parTrainerNo)

                    command.ExecuteNonQuery()
                    connection.Close()
                    GetTrainers()

                Catch ex As Exception
                    MessageBox.Show(ex.ToString)
                End Try



            Case "UPDATE"

                Try
                    Dim connection As New OleDb.OleDbConnection
                    Dim command As New OleDb.OleDbCommand


                    connection.ConnectionString = path
                    connection.Open()

                    command.Connection = connection
                    command.CommandText = "UPDATE Trainer SET Trainer_Name=@Name, Trainer_Surname=@Surname, Contact_No=@ContactNo, Class_Type=@ClassType WHERE ID = @ID"


                    Dim parName = New OleDb.OleDbParameter("@Name", txtName.Text)
                    Dim parSurname = New OleDb.OleDbParameter("@Surname", txtSurnamr.Text)
                    Dim parID = New OleDb.OleDbParameter("@ID", txtID.Text)
                    Dim parContactNo = New OleDb.OleDbParameter("@ContactNo", txtContactNo.Text)
                    Dim parClassType = New OleDb.OleDbParameter("@ClassType", txtClassType.Text)



                    'Adding Parameters to the command object
                    command.Parameters.Add(ParName)
                    command.Parameters.Add(parSurname)
                    command.Parameters.Add(parID)
                    command.Parameters.Add(parContactNo)
                    command.Parameters.Add(parClassType)


                    'Executing Parameters
                    command.ExecuteNonQuery()
                    connection.Close()
                    GetTrainers()

                Catch ex As Exception
                    MessageBox.Show(ex.ToString())

                End Try

            Case Else
                MessageBox.Show("Nothing to Submit")

        End Select

        Mode = ""
        grvTrainer.Enabled = True
        btnSubmit.Enabled = False
        btnCancel.Enabled = False

        btnAdd.Enabled = True
        btnDelete.Enabled = True
        btnUpdate.Enabled = True

    End Sub

    Private Sub grvTrainer_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles grvTrainer.CellContentClick

        Dim ID As Integer

        If Integer.TryParse(grvTrainer.CurrentRow.Cells("ID").Value.ToString(), ID) Then
            GetTrainer(ID)
        End If

    End Sub

    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click

        grvTrainer.Enabled = True
        btnSubmit.Enabled = False
        btnCancel.Enabled = False

        btnAdd.Enabled = True
        btnDelete.Enabled = True
        btnUpdate.Enabled = True
        Mode = ""

        If grvTrainer.Rows.Count > 0 Then
            Dim ID As Integer

            If Integer.TryParse(grvTrainer.CurrentRow.Cells("ID").Value.ToString(), ID) Then
                GetTrainer(ID)
            End If

            txtID.Text = ""
            txtName.Text = ""
            txtSurnamr.Text = ""
            txtContactNo.Text = ""
            txtClassType.Text = ""
            txtmonthlysalary.Text = ""
            txtScaleID.Text = ""
            txtTrainerNo.Text = ""
        End If

    End Sub

    Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click

        btnAdd.Enabled = False
        btnDelete.Enabled = False
        btnUpdate.Enabled = False

        btnSubmit.Enabled = True
        btnCancel.Enabled = True

        Mode = "UPDATE"

    End Sub

    Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Application.Exit()
    End Sub

   
End Class 

Open in new window

0
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41812194
and just where is your search button?
0
 

Author Comment

by:Swazi Nkosi
ID: 41812203
I haven't added it. That why im asking for help so that I could add it in my code
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Swazi Nkosi
ID: 41812233
Can anyone assist me, please
0
 

Author Comment

by:Swazi Nkosi
ID: 41812249
@DavidJohnson

Do you have the code for the search button?
0
 
LVL 80

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points (awarded by participants)
ID: 41834740
What do you want to search? Please note that I don't have your database or your forms so I cannot read your mind..

Create a Txtbox txtSearch and a submit button
Button_99_Onclick Event so something on the line of

  connection.ConnectionString = path
            connection.Open()
            command.Connection = connection
            command.CommandText = "SELECT* FROM Trainer where Trainer_NO=" + TxtSearch.text
            table.Load(command.ExecuteReader())
            connection.Close()
            grvTrainer.DataSurce = table

Open in new window

0
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41859952
asked and answered with no feedback
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question