ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 22nd, 2012, 03:16 PM
Kieranw7261 Kieranw7261 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2008
Posts: 10 Kieranw7261 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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();

Reply With Quote
  #2  
Old March 22nd, 2012, 08:13 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,235 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 27 m 16 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

Reply With Quote
  #3  
Old March 23rd, 2012, 03:58 PM
Kieranw7261 Kieranw7261 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2008
Posts: 10 Kieranw7261 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m 20 sec
Reputation Power: 0
Hi there

Thank you for your response.

The website is connected to a database through a data model. That is how we have been told how to do it.


cmpkwoodEntities is the model.

Order is the database table.

Code:
using (cmpkwoodEntities context = new
      cmpkwoodEntities())
{

    Order order = new Order();

    order = context.Orders.SingleOrDefault(c => c.OrderID == ID);


Im not overly sure but I would hope this helps you help me

Reply With Quote
  #4  
Old March 23rd, 2012, 09:42 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,235 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 27 m 16 sec
Reputation Power: 4445
Is this asp.NET? If so maybe try our NET forum, this forum is mostly classic asp with vbscript. I don't have any idea about your issue, sorry.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Database Search If No Result

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap