Monday, March 3, 2008

2008 Scripting Games!! Beg. Event 9

My Solution for Event 9 of the 2008 Scripting Games.

   1:  $mdb = "c:\Scripts\pool.mdb"
   2:  $ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$mdb"
   3:  $Conn = new-object System.Data.OleDb.OleDbConnection($connString)
   4:  $conn.open() 
   5:  $cmd = new-object System.Data.OleDb.OleDbCommand("SELECT * from SwimmingPool",$Conn)
   6:  $da = new-Object System.Data.OleDb.OleDbDataAdapter($cmd)
   7:  $dt = new-Object system.Data.Datatable
   8:  [void]$da.Fill($dt)
   9:  $dt | % { 
  10:      "Name: " + $_.customer
  11:      if($_.slope) {"Volume of Water:" + $_.Length * $_.Width * (($_.SStart + $_.SEnd) / 2)*1000 }
  12:      else {"Volume of Water:" + $_.Length * $_.Width * $_.Depth * 1000 }
  13:  }
  14:  
  15:  $conn.close()

No comments: