W
Wing
Hi all,
I am writing a function that can change the value "Quantity" in the
selected row of MS SQL table "shoppingCart", my code is showing below
------------------------------------------------------
static void addQuantity(int rowNum, int oldQuantity)
{
int newQuantity = oldQuantity++;
SqlConnection thisConnection = new SqlConnection
(@"Data Source=(local);Integrated Security=SSPI;" +
"Initial Catalog=PhotoDB");
thisConnection.Open();
SqlCommand AddQuantity = thisConnection.CreateCommand();
AddQuantity.CommandText = "UPDATE ShoppingCart SET Quantity =
'"+newQuantity+"' WHERE RecordID = '"+rowNum+"'";
AddQuantity.ExecuteReader();
thisConnection.Close();
}
after I call this function, no running error occured, but the Quantity
value hasn't increased by 1, the sql server doesn't recognize the
variable "newQuantity" in my UPDATE statement. However, when I replace
the variable "newQuantity" with number (eg 3), the Quantity value does
change to 3 after calling the function.
Does the UPDATE statement accept the variable like WHERE statement
does???
If UPDATE statement does accept variable, what should I change in the
statement?
If UPDATE statement doesn't accept variable, is there any other way to
solve?
thank for your time.
wing
I am writing a function that can change the value "Quantity" in the
selected row of MS SQL table "shoppingCart", my code is showing below
------------------------------------------------------
static void addQuantity(int rowNum, int oldQuantity)
{
int newQuantity = oldQuantity++;
SqlConnection thisConnection = new SqlConnection
(@"Data Source=(local);Integrated Security=SSPI;" +
"Initial Catalog=PhotoDB");
thisConnection.Open();
SqlCommand AddQuantity = thisConnection.CreateCommand();
AddQuantity.CommandText = "UPDATE ShoppingCart SET Quantity =
'"+newQuantity+"' WHERE RecordID = '"+rowNum+"'";
AddQuantity.ExecuteReader();
thisConnection.Close();
}
after I call this function, no running error occured, but the Quantity
value hasn't increased by 1, the sql server doesn't recognize the
variable "newQuantity" in my UPDATE statement. However, when I replace
the variable "newQuantity" with number (eg 3), the Quantity value does
change to 3 after calling the function.
Does the UPDATE statement accept the variable like WHERE statement
does???
If UPDATE statement does accept variable, what should I change in the
statement?
If UPDATE statement doesn't accept variable, is there any other way to
solve?
thank for your time.
wing