使用下面的代碼,我得到的錯誤:varchar數據類型爲datetime數據類型的轉換導致超出範圍的值使用腳本
Exception calling "Fill" with "1" argument(s): "The conversion of a varchar data type to a datetime data type resulted in an out-of-range value." At C:\Users\username\Desktop\TEST.ps1:47 char:1 + $CommandCompl.fill($dt7) | out-null + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SqlException
$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (200, 25)
$Date = (get-date).ToString("yyyyMMdd")
Clear
$SQLTableCOMPLIA = 'abc'
$SQLServerCOMPLIA = "123.123.123.123"
$SQLDBNameCOMPLIA = "test"
$UsernameCOMPLIA = "abc"
$PasswordCOMPLIA = "pasword"
$SQLServerLANDESK = "cba\test1"
$SqlConnectionLANDESK = New-Object System.Data.SqlClient.SqlConnection
$global:dt = new-object System.Data.DataTable
$dr = ""
$LONA = ""
$o = 0
$j = 0
$globalvuln , $globalNotvuln = 0
$global:dt7 = new-object System.Data.DataTable
$SqlConnectionCOMPLIA = New-Object System.Data.SqlClient.SqlConnection
$SqlConnectionCOMPLIA.ConnectionString = "Server=$SQLServerCOMPLIA; Database=$SQLDBNameCOMPLIA;uid=$UsernameCOMPLIA; pwd=$PasswordCOMPLIA"
$SqlConnectionCOMPLIA.Open() | out-null
$QueryCompl = "SELECT TOP 1 CONVERT(datetime,left(LD_publishdate,10),103) as R FROM vulns order by R DESC"
$CommandCompl = new-object System.Data.SqlClient.SqlDataAdapter ($QueryCompl, $SqlConnectionCOMPLIA)
$CommandCompl.fill($dt7) | out-null
我是什麼做錯了?我該如何解決這個問題?
我猜你的LD_publishdate列有無效的值,比如30天的月份31st或者這些行的內容。它基本上是自由文本,對吧? –
@MegaTron是varchar類型並允許Null。這是你問的嗎? –
'select convert(datetime,left('2015-06-31',10),103)'例如給出您收到的錯誤。空值不。所以我認爲這是你的問題。 –