hullo frenz,
i am designing an employee database.
the records are displayed on a master (emp.vb) form whereas the search button is on a seaparate form(emp_search.vb).

hw do i code the search button on the 'emp_search.vb' page so that this form closes automatically and den the records are displayed on the 'emp.vb' form.

on what event should i code?
also if i code on the clik event of a button on emp.vb form den as soon as the search form is closed then the searched data is lost and d original records are displayed. ie the entire database.

plz do help me in dis regard
riddhi

Ok, since you don't have any code so far, I'll give you an example how to get data from data base and display it using datagridview

Assuming you already have a connection to your database named "conn"

On your Form1 drag 1 DatagridView so it will be DatagridView1
Create a global variable. Ex: myVariable
create a sub like below

Public myVariable As String

Private sub DataViewer()
Dim sql as String =" Select * FROM yourtable WHERE EmployeeID = '" & myVariable &"'" 
Dim da As New Oledb.OledbDataAdapter(sql, conn)
Dim ds As New DataSet
Dim dt As DataTable
da.Fill(ds)
dt = ds.Tables(0)

'let's assume our table has only 5 fields
'we will fill our datagridview using a custom format

Dim col0 As New DatagridviewTexboxColumn
col0.DataPropertyName = "EmployeeID" 'column 0 is assigned for your Employees ID number
col0.HeaderText = "Emp. ID Number"
col0.Width = 150
DatagridView1.Columns.Add(col0)

Dim col1 As New DatagridviewTexboxColumn
col1.DataPropertyName = "FirstName" 
col1.HeaderText = "First Name"
col1.Width = 200
DatagridView1.Columns.Add(col1)

Dim col2 As New DatagridviewTexboxColumn
col2.DataPropertyName = "MiddleName" 
col2.HeaderText = "Middle Name"
col2.Width = 200
DatagridView1.Columns.Add(col2)

Dim col3 As New DatagridviewTexboxColumn
col3.DataPropertyName = "LastName" 
col3.HeaderText = "Last Name"
col3.Width = 200
DatagridView1.Columns.Add(col3)

Dim col4 As New DatagridviewTexboxColumn
col4.DataPropertyName = "Age" 
col4.HeaderText = "Age"
col4.Width = 100
DatagridView1.Columns.Add(col4)

Dim col5 As New DatagridviewTexboxColumn
col5.DataPropertyName = "CivilStatus"
col5.HeaderText = "Civil Status"
col5.Width = 100
DatagridView1.Columns.Add(col5)

With DatagridView1
      .Datasource = dt
      .RowHeadersVisible = False 'we'll not display row headers
      .ReadOnly =True 'we'll make it non editable
End Sub

  Private Sub Form1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
  Select Case myVariable
       Case ""
          DatagridView1.Datasource = Nothing
        Case Else
        DataViewer()
  End Select
    End Sub

On Form2 create a 1 combobox and 1 button
let's fill the combobox with names from our database on Form2_Load event

Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Create a connection to your database (con1)
        'I'm only assuming that "con1" is your connection variable since i don't know your connection strings

        Dim da As New Oledb.OledbDataAdapter("SELECT FirstName FROM yourEployeesTable ORDER BY FirstName asc", con1)
       Dim ds As New DataSet
       Dim dt As DataTable, row As DataRow
       da.Fill(ds)
       dt = ds.Tables(0)
       For each row in dt.Rows()
        Combobox1.Items.Add(row("FirstName")
       Next
    End Sub

 Private Sub Combobox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Combobox1.TextChanged
On Error Resume Next
Dim Frm1 As New Form1
Select Case Combobox1.Text
   Case ""
   Form1.myVariable =""

   Case Else
   Dim da As New Oledb.OledbDataAdapter("Select EmployeeID FROM yourEmployeeTable WHERE FirstName = '" & Combobox1.Text &"'", con1)
  Dim ds As New DataSet
  da.Fill(ds)
  If ds.Tables(0).Rows.Count = 1 Then
      Form1.myVariable = ds.Tables(0).Rows(0).Item("EmployeeID")
  End if
End Select
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Me.Close
End Sub

This will just give you an idea how to get and display your data
you can modify the codes as to your requirement.

Hope this will guide you to your project

This article has been dead for over six months. Start a new discussion instead.