I have two tables
Employer
Employee
Employer Table:
I have one field
EmployerID (pk Key assigned to it)
Employee Table:
EmployerID(pk Key assigned to it)
IDEmployer(fk key assigned to it,and Allow Nulls:Checked)
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")
con.Open()
_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
Try
Dim SampleCommand As New SqlCommand()
Dim SampleDataAdapter = New SqlDataAdapter()
SampleCommand.CommandText = _string
SampleCommand.Connection = con
SampleDataAdapter.SelectCommand = SampleCommand
SampleDataAdapter.Fill(SampleSource)
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
Throw
End Try
Return TableView
End Function
End Class