Manawoba michael

Manawoba michael

  • NA
  • 10
  • 2.9k

comparing gridview values to database values

Mar 22 2019 4:06 AM
hi i am michael, thank you very much for your immediate response to my question. this is a follow up question to the topic: comparing gridview values to database values. maybe  my question was not clear enough therefore i wish to explain further for a better solution to my problem.
i have a gridview in asp.net with columns productId, PurchaseQuantity and Price. i want to write a method to call under checkout button to check stock level. what i want to do is that when a customer click on checkout button the method will be call to check stock quantity in database to purchase quantity in gridview. if the stock quantity in database is less than purchase quantity, the specific product out of stock entire row in gridview will colored Black else the customer can proceed to checkout. below is my code. i hope my question will be understandable to you this time. thanks
 
public void CheckStockLevel()
{
int DBQty = 0;

for (int i = 0; i < gvCartItems.Rows.Count; i++)
{
con = new ConnectionClass();

String pid = gvCartItems.Rows[i].Cells[1].Text;
string gvQty = gvCartItems.Rows[i].Cells[4].Text;

dr = con.DataReader("SELECT Quantity FROM ProducesTb WHERE ProduceId = '" + pid + "'");
while(dr.Read())
{
DBQty = dr.GetInt32(0);
//dr.Close();
}

int gridQty;
int.TryParse(gvQty, out gridQty);

if (DBQty < gridQty)
{
gvCartItems.Rows[i].BackColor = System.Drawing.Color.Black;
}
con.CloseConnection();
}

Answers (1)