Power Shell调用c#读取sqlserver数据

$server = "192.168.255.1"
$uid = "sa"
$db="xx"
$pwd="a@123456"


$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
 
$CnnString ="Server = $server; Database = $db;User Id = $uid; Password = $pwd" 
$SqlConnection.ConnectionString = $CnnString 
$CC = $SqlConnection.CreateCommand(); 
if (-not ($SqlConnection.State -like "Open")) { $SqlConnection.Open() } 

$cc.CommandText=" 
select top(5) ICode from tblProduct
" 
$list = $cc.ExecuteReader()

while($list.Read()){
	[System.Console]::WriteLine($list["ICode"])
}


$SqlConnection.Close();

[System.Diagnostics.Process]::Start("chrome.exe","192.168.255.1")

  

posted @ 2022-05-06 08:20  Ender.Lu  阅读(64)  评论(0编辑  收藏  举报