0 Replies - 658 Views - Last Post: 17 February 2013 - 04:49 AM Rate Topic: -----

#1 chdboy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 26-July 12

How to relate two sql tables?

Posted 17 February 2013 - 04:49 AM

I have two tables

Employer Table:
I have many field
EmployerID (pk Key assigned to it)
and more columns
Employee Table:
EmployerID(pk,fk Key assigned to it)
and more columns
Now my question is how to relate two tables ,that I will now that who works for who?

currently with my code nothing(No values are being returned)
 Public Function DGVload_testsql() As DataView
        Dim con = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Danial\documents\visual studio 2010\Projects\ESI_PF_Payroll_V1\ESI_PF_Payroll_V1\Pay.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
        '_string = "select * from Employee inner join Employer on Employee.IDEmployer = Employer.EmployerID"
        'Dim _String2 As String = "ALTER TABLE Employee add CONSTRAINT fk_IDEmployer FOREIGN KEY (IDEmployer)  REFERENCES Employee (EmployerID)"
        _string = "select Employer.Firstname,Employee.Firstname from Employee inner join Employer on Employee.IDEmployer = Employer.EmployerID"
        Dim SampleSource As New DataSet
        Dim TableView As DataView
            Dim SampleCommand As New SqlCommand()
            Dim SampleDataAdapter = New SqlDataAdapter()
            SampleCommand.CommandText = _string
            SampleCommand.Connection = con
            SampleDataAdapter.SelectCommand = SampleCommand
            TableView = SampleSource.Tables(0).DefaultView
            'Use colors in DataGridView
            Test_dgv_sql.GridColor = Color.Red
            Test_dgv_sql.CellBorderStyle = DataGridViewCellBorderStyle.None
            Test_dgv_sql.BackgroundColor = Color.LightGray

            Test_dgv_sql.DefaultCellStyle.SelectionBackColor = Color.Brown
            'DGV1.DefaultCellStyle.SelectionForeColor = Color.Yellow

            Test_dgv_sql.DefaultCellStyle.WrapMode = DataGridViewTriState.[True]

            Test_dgv_sql.SelectionMode = DataGridViewSelectionMode.FullRowSelect
            Test_dgv_sql.AllowUserToResizeColumns = False

            Test_dgv_sql.RowsDefaultCellStyle.BackColor = Color.Bisque
            Test_dgv_sql.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige

            Test_dgv_sql.ColumnHeadersDefaultCellStyle.BackColor = Color.DarkRed
            Test_dgv_sql.ColumnHeadersDefaultCellStyle.ForeColor = Color.DarkGray

            'cells and rows height in DataGridView
            Dim row As DataGridViewRow = Me.Test_dgv_sql.RowTemplate
            row.DefaultCellStyle.BackColor = Color.Bisque
            row.Height = 30
            row.MinimumHeight = 15

        Catch ex As Exception
        End Try
        Return TableView
    End Function
End Class

This post has been edited by chdboy: 17 February 2013 - 06:26 AM

Is This A Good Question/Topic? 0
  • +

Page 1 of 1