Pointing to the current record identifier

  • Thread starter Thread starter Stephan Bour
  • Start date Start date
S

Stephan Bour

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.
 
Back
Top