View Single Post
Old May 14th, 2014, 09:34 AM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

You need to do something with the results from the command. Currently, you loop over the data and output it to the console which isn't all that useful in a web application.

You need to add some if logic that alerts the message whenever some row in your data set matches your criteria. I think, but that's only a wild guess as I am still unsure what you're trying to accomplish) that you may need a WHERE clause for a product ID in your SQL statement. Then you can read your data and inside the while (dr.Read()) call check the return value and if it matches some condition then output your alert. E.g.:

while (rdr.Read())
  if (rdr[0].ToString == "Whatever you're cheking"))
     string message = "Limit stock has been reached!";
                 ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + message + "');", true);
Hope this helps,

Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!