2013-10-01 2 views
0

Привет Я пытаюсь обновить столбец, хотя, похоже, не работает. Он извлекает данные и преобразует дату в строку, но раздел обновления моего кода ниже не хочет вносить изменения, внесенные Powershell.Обновление Powershell SQL Server column

## connect to db and do stuff 
$Connection = new-object system.data.SqlClient.SQLConnection("Data Source=  (local);Integrated Security=SSPI;Initial Catalog=TESTDB"); 
$sqlqry = "select row_id, DestFileName from FL_Input Where DestFileName like '%[0-9] '  + 'Jan%' + ' [0-9]%'" 
$Command = new-object system.data.sqlclient.sqlcommand 
$Command.CommandText = $sqlqry 
$Command.Connection = $Connection 
$Connection.Open() 

$UpdateCmd = new-object System.Data.SqlClient.SqlCommand 
$UpdateCmd.Connection = $Connection 

## for each filename, update timestamp - this replaces your $file in $files loop. 
$Result = $Command.ExecuteReader() 
while ($Result.Read()) { 

$destfile = $Result['DestFileName'] 
$srcfile = $destfile 
$row_id = $Result['row_id'] 

## do all your regex stuff here 

$destfile -match '\d{2}\s\w+\s\d{2,4}' | Out-Null <# Test #> 
$destfile -match '\d{2}\-\w+\-\d{4}' | Out-Null <# Test #> 

$destFile -replace "$(($matches).values)" , "$(get-date "$(($matches).Values)" -Format  yyyyMMdd)" 

write-host "{0}->{1}" -f $destfile, $srcfile 

# when you're finished doing your regex, push the result result back to the db: 
$updateqry = "update FL_Input set DestFileName='{0}' WHERE Row_ID = {1} " -f $destfile, $row_id 
$UpdateCmd.CommandText = $updateqry 
$UpdateCmd.ExecuteNonQuery() 

} 

## all done 
$Connection.Close 

ответ

0

Вы не пропуская одиночные кавычки row_id например .:

$updateqry = "update FL_Input set DestFileName='$destfile' WHERE Row_ID = '$row_id'"