Discuss Database Search If No Result in the ASP Programming forum on Dev Shed. Database Search If No Result ASP Programming forum discussing Active Server Pages coding techniques and problem solving methods. Use VBScript or Jscript to make dynamic web applications.
Posts: 10
Time spent in forums: 2 h 12 m 20 sec
Reputation Power: 0
Database Search If No Result
Hi there,
I am working on a project.
upon clicking a button the users data entry (order number) is used to search the database. I have the code to search the database below but I dont know what code to use to perform an error if the order number doesnt exist. Could anybody help. Im new to ASP and dont fully understand all the keywords available or the structures of if statements within it. Any help would be greatly appreciated.
Code:
Int64 ID = new Int64();
ID = Convert.ToInt64(txtID.Text);
using (cmpkwoodEntities context = new
cmpkwoodEntities())
{
Order order = new Order();
order = context.Orders.SingleOrDefault(c => c.OrderID == ID);
lblDate.Text = order.Date.ToShortDateString();
lblCustomerForename.Text = order.Customer.Forename;
lblCustomerSurname.Text = order.Customer.Surname;
lblCity.Text = order.Customer.City;
lblPostcode.Text = order.Customer.Postcode;
OrderItem orderitem = new OrderItem();
orderitem = context.OrderItems.SingleOrDefault(c => c.OrderID == ID);
lblOrderID.Text = orderitem.OrderID.ToString();
lblProductID.Text = orderitem.ProductID.ToString();
Product product = new Product();
product = context.Products.SingleOrDefault(c => c.ProductID == orderitem.ProductID);
lblProductName.Text = product.Name.ToString();
Posts: 14,239
Time spent in forums: 1 Month 4 Weeks 15 h 20 m 7 sec
Reputation Power: 4445
I don't see any reference to any database in the code you posted.
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi