小编Mas*_*all的帖子

将对象数组转换为字符串数组是否使用对象的 toString() 方法?

我需要使用toString()对象的方法并将其放入数组中。我想知道,如果我将数组转换为 a String[],它会使用该toString()方法吗?

例如:

public static String[] toStringArray(MyObject[] myObjects) {
    // Will this return the toString() representation of each object?
    return (String[])myObjects;
}
Run Code Online (Sandbox Code Playgroud)

java arrays string object

2
推荐指数
1
解决办法
61
查看次数

SqlClient.ExecuteNonQuery不返回行数

我一直在处理这个问题.我有一个简单的PowerShell函数,它接受SQL Server的开放连接和包含SQL命令的String,并对服务器运行它.该函数应返回一个整数值,表示已更新的行数.但是,它正在输出有关该方法的信息.

码:

function Invoke-MSSQLNonQuery () {
    param (
        [System.Data.SqlClient.SqlConnection]$Connection,
        [string]$Command
    )

    # Create the SQL Command Ojbect
    $SQLCommand = New-Object System.Data.SqlClient.SqlCommand

    # Set the Command Text and Connection for the Command
    $SQLCommand.CommandText=$Command
    $SQLCommand.Connection=$Connection

    # Run command and return the rows affected
    [int]($SQLCommand.ExecuteNonQuery | Out-String)
}
Run Code Online (Sandbox Code Playgroud)

但是,执行时,我收到以下错误:

Cannot convert value "
OverloadDefinitions
-------------------
int ExecuteNonQuery()
int IDbCommand.ExecuteNonQuery()

" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\_Local\playground\Mason\UpdateFromInventory.ps1:153 char:5
+     [int]($SQLCommand.ExecuteNonQuery | Out-String)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + …
Run Code Online (Sandbox Code Playgroud)

powershell return-type sqlclient

2
推荐指数
1
解决办法
159
查看次数

标签 统计

arrays ×1

java ×1

object ×1

powershell ×1

return-type ×1

sqlclient ×1

string ×1