首先必须安装了Mysql 5.0 Connector .net 5.0的driver,
下载地址:http://www.mysql.org/downloads/connector/net/5.0.html
然后编写如下代码。
[void][system.reflection.Assembly]::LoadFrom("D:\mysql\MySQL Connector Net 5.0.8.1\Binaries\.NET 2.0\MySQL.Data.dll")
$myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection
$myconnection.ConnectionString = "server=localhost;user id=root;password=root;database=mrpII;pooling=false"
$myconnection.Open()
$mycommand = New-Object MySql.Data.MySqlClient.MySqlCommand
$mycommand.Connection = $myconnection
$mycommand.CommandText = "SELECT * from MRP_BOM"
$adapter = new-object MySql.Data.MySqlClient.MySqlDataAdapter
$adapter.SelectCommand = $mycommand
$ds = new-object System.Data.DataSet
$adapter.Fill($ds)
$myconnection.close()
$ds.Tables[0] |Format-Table #非常Cool的输出效果,如下图
真是cool毙了。