DataTable Load Method "Nutting Up" In Powershell


when use load method of datatable object in powershell, following error:

cannot find overload "load" , argument count: "0".
@ line:10 char:9
+ $dt.load <<<< ()
    + categoryinfo          : notspecified: (:) [], methodexception
    + fullyqualifiederrorid : methodcountcouldnotfindbest

the load method works in vb.net , c#. happened?

code

$con = new-object system.data.sqlclient.sqlconnection
$cmd = new-object system.data.sqlclient.sqlcommand
$dt = new-object system.data.datatable
$con.connectionstring = "server=$srv;database=$database;integrated security=sspi"
$con.open | out-null
$cmd.commandtext = "select top 100 * [dbo].[table]"
$cmd.connection = $con
$dr = $cmd.executereader | out-null
$dt.load($dr)


dj baby anne's biggest fan................

i got something. small changes make difference:

$con = new-object system.data.sqlclient.sqlconnection
$cmd = new-object system.data.sqlclient.sqlcommand
$dt = new-object system.data.datatable

$con.connectionstring = "server=$srv;database=$database;integrated security=sspi"
$con.open()
$cmd.commandtext = "select top 100 * [dbo].[table]"
$cmd.connection = $con
$dr = $cmd.executereader()
$dt.load($dr)
$dt


dj baby anne's biggest fan................


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

CRL Revocation always failed

Failed to query the results of bpa xpath

0x300000d errors in Microsoft Remote Desktop client