Currently, I have a DataGridView (DGV) that brings in three columns (Employee_ID, User_ID, ID_Type) from two different MS Access tables. However, I would like to add a fourth column (User_Name) from Active Directory (AD) by looking up the User's name from AD using the Employee_ID. In the below code, do I use a for each loop? Any assistance would be greatly appreciated.
Thanks!
GCRANE
Here is the code I have so far:
Private Sub MainView_Load(sender As Object, e As EventArgs) Handles MyBase.Load
IDType = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = Drive:\Path\Filename.accdb")
IDType.Open()
Dim ResultsCommand As OleDbCommand = Nothing
Dim ResultsAdapter As New OleDbDataAdapter
Dim ResultsTable As New DataTable
Try
'establish command object and data adapter
ResultsCommand = New OleDbCommand("SELECT UserIDs.EmpID AS Employee_ID, UserIDs.IDType AS User_ID, IDDesc.[Desc] AS ID_Type FROM UserIDs INNER JOIN IDDesc ON UserIDs.IDDesc = IDDesc.ID ORDER BY UserIDs.EmpID", IDType)
ResultsAdapter.SelectCommand = ResultsCommand
ResultsAdapter.Fill(ResultsTable)
'bind grid view to data table
dgvIDType.DataSource = ResultsTable
'lblRecords.Text = ResultsTable.Rows.Count.ToString
'ADD USER NAME COLUMN
Dim strUserID As String
dgvIDType.Columns.Add("username", "User_Name")
'FOR EACH LOOP?
Try
dgvIDType.User_Name = GetUserName(domainDN, strUserID)
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Information, "SYSTEM MESSAGE")
End Try
Catch ex As Exception
MessageBox.Show(ex.Message, "Error in Processing SQL", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
ResultsCommand.Dispose()
ResultsAdapter.Dispose()
ResultsTable.Dispose()
End Sub
Thanks!
GCRANE
Here is the code I have so far:
Private Sub MainView_Load(sender As Object, e As EventArgs) Handles MyBase.Load
IDType = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = Drive:\Path\Filename.accdb")
IDType.Open()
Dim ResultsCommand As OleDbCommand = Nothing
Dim ResultsAdapter As New OleDbDataAdapter
Dim ResultsTable As New DataTable
Try
'establish command object and data adapter
ResultsCommand = New OleDbCommand("SELECT UserIDs.EmpID AS Employee_ID, UserIDs.IDType AS User_ID, IDDesc.[Desc] AS ID_Type FROM UserIDs INNER JOIN IDDesc ON UserIDs.IDDesc = IDDesc.ID ORDER BY UserIDs.EmpID", IDType)
ResultsAdapter.SelectCommand = ResultsCommand
ResultsAdapter.Fill(ResultsTable)
'bind grid view to data table
dgvIDType.DataSource = ResultsTable
'lblRecords.Text = ResultsTable.Rows.Count.ToString
'ADD USER NAME COLUMN
Dim strUserID As String
dgvIDType.Columns.Add("username", "User_Name")
'FOR EACH LOOP?
Try
dgvIDType.User_Name = GetUserName(domainDN, strUserID)
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Information, "SYSTEM MESSAGE")
End Try
Catch ex As Exception
MessageBox.Show(ex.Message, "Error in Processing SQL", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
ResultsCommand.Dispose()
ResultsAdapter.Dispose()
ResultsTable.Dispose()
End Sub