I have a datagridview that is being loaded from a dataset. This dataset is the result of a SQL Statement (which could be my problem). The MS Access Client table is the main table and contains 2 records, however, after loading the dataset, the row count is 3.
Below is the procedure where I load the dataset and then the DGV.
The Access table "tblAddressCodes" is a lookup table and the "tblClientAddr" contains only 2 records and only 1 of them should be returned in the SQL Statement.Code:Public Function LoadClientDataSet() Try strSQL = "SELECT A.clientID, A.name, B.phone, B.zipCode, B.stateCD " & _ "FROM (tblClients A LEFT JOIN tblClientAddr B ON A.addrType = B.addrID) " & _ "LEFT JOIN tblAddressCodes C ON B.addrID = C.addrID " & _ "WHERE A.clientID <> NULL" Dim clientADP As New OleDb.OleDbDataAdapter(strSQL, oConn) clientADP.Fill(rsClientGrid, "tblClients") Catch ex As Exception MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Function ' ' ' Private Sub LoadClientGrid() Try 'grdClientList.Rows.Clear() For Each row As DataRow In rsClientGrid.Tables("tblClients").Rows Dim grdRow As New DataGridViewRow Dim dgvCell As DataGridViewCell dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = row.Item(0) grdRow.Cells.Add(dgvCell) dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = row.Item(1) grdRow.Cells.Add(dgvCell) dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = row.Item(2) grdRow.Cells.Add(dgvCell) dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = row.Item(3) grdRow.Cells.Add(dgvCell) dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = row.Item(4) grdRow.Cells.Add(dgvCell) grdClientList.Rows.Add(grdRow) Next Catch ex As Exception MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub
Hope this makes sense.
Thanks,




Reply With Quote