title: getting database table to show in dataGridView in powershell
body: <p>I am building a powershell gui application that pulls info from a database table that I need to monitor. I am having an issue getting that data into the datagridview. I can do it manually so it shows at least one entry but I need it to show the full table results. This is my 1st powershell GUI project. </p>
  
  <pre><code>add-type -AssemblyName System.Data.OracleClient
  
  Function ShowJobsInQueue()
  
  {
  
  ## To connect by Service Name
  $ora_server = "dm01-scan.campsys.com"
  $ora_user = "appuser"
  $ora_pass = "hillary"
  $ora_servicename = "dbcamp1_svc.campsys.com"
  
  
  ## by ServiceName
  $connection = new-object system.data.oracleclient.oracleconnection("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$ora_server)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=$ora_servicename)));User Id=$ora_user;Password=$ora_pass;")
  
  $connection.open()
  
  $query = "SELECT * FROM ASYNCJOB WHERE TRUNC(START_DATE)= TRUNC(SYSDATE) AND job_type &lt;&gt;15 and STATUS in ('1','2') ORDER BY ASYNCJOB_ID DESC"
  
  $list_set = new-object system.data.dataset
  #$array = New-Object System.Collections.ArrayList
  #$array.AddRange($list_table)
  #$dataGridView.DataSource = $array 
  $list_adapter = new-object system.data.oracleclient.oracledataadapter($query, $connection)
  $list_adapter.Fill($list_set) | Out-Null
  $list_table = new-object system.data.datatable
  $list_table = $list_set.Tables[0]
  $DBValues = $list_table
  
  while($dataGridView.Rows.Count -lt $list_table.Count) {
      $dataGridView.Rows.Add() | Out-Null
  }
  
  for ($i=0;$i -lt $list_table.Count ;$i++) {
      $dataGridView.rows[$i].Cells[0].Value = $list_table[$i].Item("ASYNCJOB_ID")
  }
  
  $connection.close()
  $form.refresh()
  
  }
  
  
  $OnLoadForm_UpdateGrid= 
  { 
     ShowJobsInQueue
  
  } 
  
  ########################################
  
  Add-Type -AssemblyName System.Windows.Forms
  
  $Form = New-Object system.Windows.Forms.Form
  $Form.Text = "Report Monitor"
  $Form.TopMost = $true
  $Form.minimumSize = New-Object System.Drawing.Size(1024,750)
  $Form.maximumSize = New-Object System.Drawing.Size(1024,750)
  
  $dataGridView = New-Object System.Windows.Forms.DataGridView
  $dataGridView.Size=New-Object System.Drawing.Size(1024,570)
  $form.Controls.Add($dataGridView)
  
  
  $buttonRefresh = New-Object system.windows.Forms.Button
  $buttonRefresh.Text = "Refresh"
  $buttonRefresh.Width = 65
  $buttonRefresh.Height = 35
  $buttonRefresh.Add_Click({
         $Form.close()
  })
  $buttonRefresh.location = new-object system.drawing.point(338,600)
  $buttonRefresh.Font = "Microsoft Sans Serif,10"
  $Form.controls.Add($buttonRefresh)
  
  
  $buttonExit = New-Object system.windows.Forms.Button
  $buttonExit.Text = "Exit"
  $buttonExit.Width = 65
  $buttonExit.Height = 35
  $buttonExit.Add_Click({
        $Form.close()
  })
  $buttonExit.location = new-object system.drawing.point(500,600)
  $buttonExit.Font = "Microsoft Sans Serif,10"
  $Form.controls.Add($buttonExit)
  
  #Create an unbound DataGridView by declaring a column count.
  $dataGridView.ColumnCount = 6
  $dataGridView.ColumnHeadersVisible = $true
  
  #Set the column header names.
  $dataGridView.Columns[0].Name = "Row#"
  $dataGridView.Columns[1].Name = "ASYNCJOB_ID"
  $dataGridView.Columns[2].Name = "USER_ID"
  $dataGridView.Columns[3].Name = "START_DATE"
  $dataGridView.Columns[4].Name = "END_DATE"
  $dataGridView.Columns[5].Name = "STATUS"
  
  
  
  #$dataGridView.Rows[0].Cells[0].Value = "Value1"
  #$dataGridView.Rows[0].Cells[1].Value = "Value2"
  #$dataGridView.Rows[0].Cells[2].Value = "Value3"
  #$dataGridView.Rows.Add();
  
  
  #############################################################
  
  $buttonOn = New-Object system.windows.Forms.RadioButton
  $buttonOn.Text = "On"
  $buttonOn.Width = 65
  $buttonOn.Height = 35
  $buttonOn.Add_Click({
  # create function to turn on auto mode
        $Form.close()
  })
  $buttonOn.location = new-object system.drawing.point(920,600)
  $buttonOn.Font = "Microsoft Sans Serif,10"
  $Form.controls.Add($buttonOn)
  
  ## button off 
  
  $buttonOff = New-Object system.windows.Forms.RadioButton
  $buttonOff.Text = "Off"
  $buttonOff.Width = 65
  $buttonOff.Height = 35
  $buttonOff.Add_Click({
        # create function to turn off auto mode
        $Form.close()
  })
  $buttonOff.location = new-object system.drawing.point(870,600)
  $buttonOff.Font = "Microsoft Sans Serif,10"
  $Form.controls.Add($buttonOff)
  
  ## end button off
  
  
  #### auto mode label
  
  $Automode = New-Object system.windows.Forms.Label
  $Automode.Text = "Auto Mode"
  $Automode.Width = 25
  $Automode.Height = 10
  $Automode.AutoSize = $true
  $Automode.location = new-object system.drawing.point(875,580)
  $Automode.Font = "Microsoft Sans Serif,10"
  $Form.controls.Add($Automode)
  
  #### end label
  
  
  #Add Form event 
  $form.add_Load($OnLoadForm_UpdateGrid) 
  
  
  [void]$Form.ShowDialog()
  $Form.Dispose()
  </code></pre>