Update Table with get-date

  • Hi,

    i want to update my table Field Date_Import=get-date -f (without time)

    TBL_Import

    [Count_Import] int NULL,

    [Count_Fault] int NULL,

    [Date_Import] date NULL

    $Command = $Connection.CreateCommand()

    $Count_Fault = $directory_file_count

    $Date_used = get-date

    $Command.CommandText ="update TBL_IMPORT set Count_Fault=$Count_Import where $Date_Import=$date_used"

    $Command.ExecuteNonQuery()

    $Connection.Close()

    What is wrong in my code ? the Problem is on where clause ..

    Many THX

    I get this Msg:

    Ausnahme beim Aufrufen von "ExecuteNonQuery" mit 0 Argument(en): "Incorrect syntax near '16'."

    Bei D:\Skripte\Count_Fault.ps1:54 Zeichen:27

    + $Command.ExecuteNonQuery <<<< ()

    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException

  • i'm guessing since you are using powershell to substitute values, the date parameter must be in single quotes;

    also, it looks like $Date_Import would get substituted too, which makes an invalid query?

    i think it's $Date_Import gets substituted with empty string, plus maybe the date issue? :

    value = 07/01/2013

    vs

    value = '07/01/2013'

    not sure why the value 16 is an error, though? is it really this is the problem?

    Count_Fault=$Count_Import

    $Command.CommandText ="update TBL_IMPORT set Count_Fault=$Count_Import where $Date_Import=$date_used"

    i think it needs to be this: the change is sublte:

    $Command.CommandText ="update TBL_IMPORT set Count_Fault=$Count_Import where Date_Import='$date_used'"

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Why are we doing this in PowerShell?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thx it's works.

  • Lowell (7/1/2013)


    i'm guessing since you are using powershell to substitute values, the date parameter must be in single quotes;

    also, it looks like $Date_Import would get substituted too, which makes an invalid query?

    i think it's $Date_Import gets substituted with empty string, plus maybe the date issue? :

    value = 07/01/2013

    vs

    value = '07/01/2013'

    not sure why the value 16 is an error, though? is it really this is the problem?

    Count_Fault=$Count_Import

    $Command.CommandText ="update TBL_IMPORT set Count_Fault=$Count_Import where $Date_Import=$date_used"

    i think it needs to be this: the change is sublte:

    $Command.CommandText ="update TBL_IMPORT set Count_Fault=$Count_Import where Date_Import='$date_used'"

    Thx it works fine 🙂

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply