Difference between revisions of "Power Shell"

Jump to navigation Jump to search
27 bytes added ,  12:28, 8 January 2010
m
Minor edit
m (Minor edit)
m (Minor edit)
Line 223: Line 223:


'''Reader Query'''
'''Reader Query'''
In theory, this should work, but it doesn't seem to.  There's something wrong with the <code>while ($results.Read())</code>, in that you end up displaying the last row returned by the SQL query multiple times
In theory, this should work, but it doesn't seem to for me.  There's something wrong with the <code>while ($results.Read())</code>, in that you end up displaying the last row returned by the SQL query multiple times.  Suspect its due to the way that a Reader object only seems to hold a result temporarily.
<pre>
<pre>
$query = "SELECT * FROM subnets;"
$query = "SELECT * FROM subnets;"
Line 237: Line 237:
</pre>
</pre>


Instead, this function seems to work perfectly (borrowed from [http://database-programming.suite101.com/article.cfm/connecting_to_mysql_from_powershell Mark Alexander Bain])I suspect it could be simplified, but it does the job I want, returning a table of results.
Instead, this approach seems to work more reliablyBy loading the data into a dataset, it becomes available for offline manipulation and isn't reliant on the database once the data is loaded in.
<pre>
<pre>
function ExecuteMySQLQuery([string]$query) {  
function ExecuteMySQLQuery([string]$query) {  

Navigation menu