Tomie
12-13-2005, 04:36 AM
Hello,
I have a really slim, simple shopping basket type thing where I have a catalog page and a buyIt page. Now I need to be able to return the number of rows which have been returned from the SQL statement which is executed. For example, if the product already exists in the tCart table then it should only update the quantity, otherwise chuck the whole new row in.
void setSQLcommand(string param) { // put SQL into command object
if(command == null) { // if no command object yet, create one
command = new OleDbCommand();
command.Connection = conn;
}
command.CommandText = param; // pass the SQL into the command object
}
void executeNonQuery(string SQL) { // issue a non-Select SQL statement
setSQLcommand(SQL); // put statement into command object
Trace.Write("ExecNQ", SQL);
conn.Open();
command.ExecuteNonQuery(); // execute SQL in DBMS
conn.Close(); // keep open for the shortest time possible
}
// SQL statement to check if the product is present in the cart * need something to count the number of returned rows !
string queryString = "SELECT * FROM tCart WHERE productCode = " + Session["sproductid"].ToString() + " AND orderID = " + "'" + Session["orderID"].ToString() + "'" + ")";
executeNonQuery(queryString );
if() { // if the product already exists in the cart
string updateSQL = "UPDATE tCart SET quantity = quantity + " + txtQuantity.Text + " WHERE WHERE productCode = " + Session["sproductid"].ToString() + " AND orderID = " + "'" + Session["orderID"].ToString() + "'" + ")"; // only update the quantity
executeNonQuery(updateSQL);
}
else {
string insertSQL = "INSERT INTO tCart (productCode, quantity, orderID) VALUES ("+ Session["sproductid"].ToString() + "," + txtQuantity.Text + "," + "'" + Session["orderID"].ToString() + "'" + ")";
executeNonQuery(insertSQL);
}
Anyone any ideas please, something which can return to me the number of rows which were found when a select statement is executed.
Thank you for any advice !
I have a really slim, simple shopping basket type thing where I have a catalog page and a buyIt page. Now I need to be able to return the number of rows which have been returned from the SQL statement which is executed. For example, if the product already exists in the tCart table then it should only update the quantity, otherwise chuck the whole new row in.
void setSQLcommand(string param) { // put SQL into command object
if(command == null) { // if no command object yet, create one
command = new OleDbCommand();
command.Connection = conn;
}
command.CommandText = param; // pass the SQL into the command object
}
void executeNonQuery(string SQL) { // issue a non-Select SQL statement
setSQLcommand(SQL); // put statement into command object
Trace.Write("ExecNQ", SQL);
conn.Open();
command.ExecuteNonQuery(); // execute SQL in DBMS
conn.Close(); // keep open for the shortest time possible
}
// SQL statement to check if the product is present in the cart * need something to count the number of returned rows !
string queryString = "SELECT * FROM tCart WHERE productCode = " + Session["sproductid"].ToString() + " AND orderID = " + "'" + Session["orderID"].ToString() + "'" + ")";
executeNonQuery(queryString );
if() { // if the product already exists in the cart
string updateSQL = "UPDATE tCart SET quantity = quantity + " + txtQuantity.Text + " WHERE WHERE productCode = " + Session["sproductid"].ToString() + " AND orderID = " + "'" + Session["orderID"].ToString() + "'" + ")"; // only update the quantity
executeNonQuery(updateSQL);
}
else {
string insertSQL = "INSERT INTO tCart (productCode, quantity, orderID) VALUES ("+ Session["sproductid"].ToString() + "," + txtQuantity.Text + "," + "'" + Session["orderID"].ToString() + "'" + ")";
executeNonQuery(insertSQL);
}
Anyone any ideas please, something which can return to me the number of rows which were found when a select statement is executed.
Thank you for any advice !