Pointing to the current record identifier

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top