Pointing to the current record identifier

Discussion in 'ASP .Net' started by Stephan Bour, Oct 27, 2003.

  1. Stephan Bour

    Stephan Bour Guest

    Hi,
    I am trying to implement a SQLServer database update inside a catch loop and
    I'm having difficulties pointing to the row to update using the current
    order's OrderID primary key Identifier in the table.

    The block:

    catch (Exception MailEx) {
    //Tag record as FAIL
    SqlCommand sqlCmd = new SqlCommand ( );
    sqlCmd.Connection = new SqlConnection ("server =
    'LMM-MB-DATA,25886';Database = 'Oligo_Order'; Trusted_Connection=Yes");
    // define insert command parameters
    sqlCmd.CommandText = "UPDATE Orders SET Tag = 'FAIL' WHERE
    OrderID = 'Order.OrderNum'";
    sqlCmd.Connection.Open ( );
    // do SET
    sqlCmd.ExecuteNonQuery ( );

    Response.Redirect("Oligo_Confirm.aspx?Error=True");

    Doesn't work: Error converting data type varchar to numeric (Order.OrderNum
    returns a String and the OrderID column in SQL is of type Numeric).
    I therefore tried this:

    Order.OrderInt = sqlCmd.Parameters["@Id"].Value.ToInt32();

    And I get this: 'object' does not contain a definition for 'ToInt32'

    If I replace 'Order.OrderNum' with an actual record Identifier in the table
    the command works fine:
    sqlCmd.CommandText = "UPDATE Orders SET Tag = 'FAIL' WHERE OrderID = 26";

    Thanks for your help.
    Stephan.
     
    Stephan Bour, Oct 27, 2003
    #1
    1. Advertising

  2. To get an int:

    System.Int32.Parse(yourstring);


    Something like that
    "Stephan Bour" <> wrote in message news:BBC2EE34.A792%...
    > Hi,
    > I am trying to implement a SQLServer database update inside a catch loop and
    > I'm having difficulties pointing to the row to update using the current
    > order's OrderID primary key Identifier in the table.
    >
    > The block:
    >
    > catch (Exception MailEx) {
    > //Tag record as FAIL
    > SqlCommand sqlCmd = new SqlCommand ( );
    > sqlCmd.Connection = new SqlConnection ("server =
    > 'LMM-MB-DATA,25886';Database = 'Oligo_Order'; Trusted_Connection=Yes");
    > // define insert command parameters
    > sqlCmd.CommandText = "UPDATE Orders SET Tag = 'FAIL' WHERE
    > OrderID = 'Order.OrderNum'";
    > sqlCmd.Connection.Open ( );
    > // do SET
    > sqlCmd.ExecuteNonQuery ( );
    >
    > Response.Redirect("Oligo_Confirm.aspx?Error=True");
    >
    > Doesn't work: Error converting data type varchar to numeric (Order.OrderNum
    > returns a String and the OrderID column in SQL is of type Numeric).
    > I therefore tried this:
    >
    > Order.OrderInt = sqlCmd.Parameters["@Id"].Value.ToInt32();
    >
    > And I get this: 'object' does not contain a definition for 'ToInt32'
    >
    > If I replace 'Order.OrderNum' with an actual record Identifier in the table
    > the command works fine:
    > sqlCmd.CommandText = "UPDATE Orders SET Tag = 'FAIL' WHERE OrderID = 26";
    >
    > Thanks for your help.
    > Stephan.
    >
     
    Chance Hopkins, Oct 27, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page