I have a very simple shopping cart app that is supposed to execute a class called OrderDB in which the gathered data is submitted to my sql database however everytime I build my application I get an error saying that orderDB cannot be found in the current
context.
The user is required to complete a wizard and onces that is done they simply click on finish and then this should happen.
Intellisense is underlining OrderDB with the message "The Name 'orderDB' does not exist in the current context." Im a touch confused because OrderDB is a class in my App_Code Folder.
Where am I going wrong with this? Any help is greatly appreciated as this is the only element holding me back on this project.
But It has started throwing this error message me now. "The type or namespace name 'OrderDB' does not exist in the namepsace 'Portal.App_Code2. (Are you missing and assembly reference)?" Hmmm, I dont think I am missing any references and if I was I wouldnt
know what it would be in this instace.
Thank you for your reply. I have checked the case of the names and they all match, I did noticed the OrderDB's name space was Portal.App_Code and the codebehind for the page I want to use it on was using namespace Purchasing. So I changed OrderDB to use
the namespace Purchasing however this has not helped. I have posted my code for both items and the directories they are in so perhaps you can pinpoint much better than I can what is wrong.
/Purchasing/Checkout.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Portal.Purchasing
{
public partial class Checkout : System.Web.UI.Page
{
private Order order;
private Customer cust;
private ShoppingCart cart;
protected void Page_Load(object sender, EventArgs e)
{
cart = (ShoppingCart)Session["cart"];
if (Session["order"] == null)
{
order = new Order(DateTime.Now,
null, (ShoppingCart)Session["cart"]);
Session["order"] = order;
}
else
{
order = (Order)Session["order"];
cart = order.Cart;
}
cust = new Customer(txtLastName.Text, txtFirstName.Text, txtEmail.Text);
order.Cust = cust;
lblSubtotal.Text = order.SubTotal.ToString("c");
lblShipping.Text = order.Shipping.ToString("c");
lblTotal.Text = order.Total.ToString("c"); cart = (ShoppingCart)Session["cart"];
if (Session["order"] == null)
{
order = new Order(DateTime.Now,
null, (ShoppingCart)Session["cart"]);
Session["order"] = order;
}
else
{
order = (Order)Session["order"];
cart = order.Cart;
}
cust = new Customer(txtLastName.Text, txtFirstName.Text, txtEmail.Text);
order.Cust = cust;
lblSubtotal.Text = order.SubTotal.ToString("c");
lblShipping.Text = order.Shipping.ToString("c");
lblTotal.Text = order.Total.ToString("c");
}
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
bool success = Portal.Purchasing.OrderDB.WriteOrder(order);
Session["cart"] = null;
Session["order"] = null;
if (success)
Response.Redirect("Completed.aspx");
else
Response.Redirect("Completed.aspx?Error=1");
}
}
}
I tried changing the namespace to just "Purchasing" however that breaks a lot more code as it underlines almost every element saying it doesnt exist in the current context which I could correct with find control I guess but none the less for the purposes
of testing I let the project build but OrderDB is still showing the same error. It seems that chaning the namespace didnt help.
Yanayaya
Member
35 Points
200 Posts
Bool success
Oct 26, 2011 01:57 PM|LINK
I have a very simple shopping cart app that is supposed to execute a class called OrderDB in which the gathered data is submitted to my sql database however everytime I build my application I get an error saying that orderDB cannot be found in the current context.
The user is required to complete a wizard and onces that is done they simply click on finish and then this should happen.
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e) { bool success = OrderDB.WriteOrder(order); Session["cart"] = null; Session["order"] = null; if (success) Response.Redirect("Completed.aspx"); else Response.Redirect("Completed.aspx?Error=1"); }Intellisense is underlining OrderDB with the message "The Name 'orderDB' does not exist in the current context." Im a touch confused because OrderDB is a class in my App_Code Folder.
Where am I going wrong with this? Any help is greatly appreciated as this is the only element holding me back on this project.
shopping
Lateef045
Star
7813 Points
1541 Posts
Re: Bool success
Oct 26, 2011 02:03 PM|LINK
Make sure you specify the correct full name (with namespaces as well) for the class.
I am sure you are missing on a very small thing.
Yanayaya
Member
35 Points
200 Posts
Re: Bool success
Oct 26, 2011 02:13 PM|LINK
Hi Lateef045, Could you please give me an example of how that would look?
Many thanks.
Lateef045
Star
7813 Points
1541 Posts
Re: Bool success
Oct 26, 2011 02:15 PM|LINK
Open your class in the App_Code folder and find out the namespace name.
If the namespace name is NameOfNameSpace then you can give this
Yanayaya
Member
35 Points
200 Posts
Re: Bool success
Oct 26, 2011 02:20 PM|LINK
As I thought. The name space is:
So I put it in as
But It has started throwing this error message me now. "The type or namespace name 'OrderDB' does not exist in the namepsace 'Portal.App_Code2. (Are you missing and assembly reference)?" Hmmm, I dont think I am missing any references and if I was I wouldnt know what it would be in this instace.
bob.vogt
Member
107 Points
48 Posts
Re: Bool success
Oct 26, 2011 02:23 PM|LINK
Be sure that the "OrderDB" class is in the correct Case i.e. It's not actually "OrderDb"
Be sure that "OrderDB" is of the correct type "Public"
Be sure that the Class in you AppCode Folder and the code behind class are under the same namespace.
If there is not namespace container in your class or codebehind class you will need to add one to both named the same.
Yanayaya
Member
35 Points
200 Posts
Re: Bool success
Oct 26, 2011 02:32 PM|LINK
Thank you for your reply. I have checked the case of the names and they all match, I did noticed the OrderDB's name space was Portal.App_Code and the codebehind for the page I want to use it on was using namespace Purchasing. So I changed OrderDB to use the namespace Purchasing however this has not helped. I have posted my code for both items and the directories they are in so perhaps you can pinpoint much better than I can what is wrong.
/Purchasing/Checkout.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Configuration; using System.Collections; using System.Web.Security; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace Portal.Purchasing { public partial class Checkout : System.Web.UI.Page { private Order order; private Customer cust; private ShoppingCart cart; protected void Page_Load(object sender, EventArgs e) { cart = (ShoppingCart)Session["cart"]; if (Session["order"] == null) { order = new Order(DateTime.Now, null, (ShoppingCart)Session["cart"]); Session["order"] = order; } else { order = (Order)Session["order"]; cart = order.Cart; } cust = new Customer(txtLastName.Text, txtFirstName.Text, txtEmail.Text); order.Cust = cust; lblSubtotal.Text = order.SubTotal.ToString("c"); lblShipping.Text = order.Shipping.ToString("c"); lblTotal.Text = order.Total.ToString("c"); cart = (ShoppingCart)Session["cart"]; if (Session["order"] == null) { order = new Order(DateTime.Now, null, (ShoppingCart)Session["cart"]); Session["order"] = order; } else { order = (Order)Session["order"]; cart = order.Cart; } cust = new Customer(txtLastName.Text, txtFirstName.Text, txtEmail.Text); order.Cust = cust; lblSubtotal.Text = order.SubTotal.ToString("c"); lblShipping.Text = order.Shipping.ToString("c"); lblTotal.Text = order.Total.ToString("c"); } protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e) { bool success = Portal.Purchasing.OrderDB.WriteOrder(order); Session["cart"] = null; Session["order"] = null; if (success) Response.Redirect("Completed.aspx"); else Response.Redirect("Completed.aspx?Error=1"); } } }/App_Code/OrderDB.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.SqlClient; namespace Portal.Purchasing { public class OrderDB { static SqTransaction tran; static SqlConnection con; public static bool WriteOrder(Order o) { string cs = WebConfigurationManager .ConnectionStrings["MuirHubProductsConnection"] .ConnectionString; con = new SqlConnection(cs); con.Open(); tran = con.BeginTransaction(); try { InsertCustomer(o.Cust); int oNum = InsertOrder(o); foreach (CartItem item in o.Cart.GetItems()) InsertItem(item, oNum); tran.Commit(); con.Close(); return true; } catch (Exception ex) { tran.RollBack(); return false; } } private static void InsertCustomer(Customer cust) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.Transaction = tran; try { cmd.CommandText = "INSERT INTO Staff " + "(lastname, firstname, email) " + "VALUES (@LastName, @FirstName, @Email)"; cmd.Parameters.AddWithValue( "@LastName", cust.LastName); cmd.Parameters.AddWithValue( "@FirstName", cust.FirstName); cmd.Parameters.AddWithValue( "@Email", cust.Email); cmd.ExecuteNonQuery(); } catch (SqlException ex) { if (ex.Number == 2627) //DuplicateKey { cmd.CommandText = "UPDATE Staff " + "SET lastname = @LastName, " + "firstname = @FirstName " + "WHERE email = @Email "; cmd.ExecuteNonQuery(); } else throw ex; } } private static int InsertOrder(Order o) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.Transaction = tran; cmd.CommandText = "INSERT INTO Orders " + "(orderdate, custemail, " + "subtotal, shipping) " + "VALUE (@OrderDate, @Custemail, " + "@subtotal, @shipping)"; cmd.Parameters.AddWithValue( "@OrderDate", DateTime.Now); cmd.Parameters.AddWithValue( "@Custemail", o.Cust.Email); cmd.Parameters.AddWithValue( "@subtotal", o.SubTotal); cmd.Parameters.AddWithValue( "@shipping", o.Shipping); cmd.ExecuteNonQuery(); cmd.CommandText = "SELECT @@IDENTITY"; return Convert.ToInt32(cmd.ExecuteScalar()); } private static void InsertItem(CartItem item, int oNum) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.Transaction = tran; cmd.CommandText = "INSERT INTO OrderItems " + "(ordernum, productid, " + "name, price, quantity_ " + "VALUES (@OrderNum,, @ProductID, " + "@Name, @Price, @Quantity)"; cmd.Parameters.AddWithValue( "@OrderNum", oNum); cmd.Parameters.AddWithValue( "@ProductID", item.ID); cmd.Parameters.AddWithValue( "@Name", item.Name); cmd.Parameters.AddWithValue( "@Price", item.Price); cmd.Parameters.AddWithValue( "@Quantity", item.Quantity); cmd.ExecuteNonQuery(); } } }bob.vogt
Member
107 Points
48 Posts
Re: Bool success
Oct 26, 2011 02:44 PM|LINK
Try changing both namespaces to just "Purchasing"
If both classes are under the same namespace in the same project you should not have to include the namespace in the method call.
Yanayaya
Member
35 Points
200 Posts
Re: Bool success
Oct 27, 2011 07:41 AM|LINK
Hi Bob,
I tried changing the namespace to just "Purchasing" however that breaks a lot more code as it underlines almost every element saying it doesnt exist in the current context which I could correct with find control I guess but none the less for the purposes of testing I let the project build but OrderDB is still showing the same error. It seems that chaning the namespace didnt help.
Mastan Oli
Contributor
5088 Points
998 Posts
Re: Bool success
Oct 27, 2011 09:48 AM|LINK
namespace changes, doesnt make much difference. try like
what you are inheriting in the checkout.aspx @ page tag? like
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Checkout.aspx.cs" Inherits="Checkout" %>
or
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Checkout.aspx.cs" Inherits="Portal.Purchasing.Checkout" %>
It should be Inherits="Portal.Purchasing.Checkout"
playingOOPS | மெய்ப்பொருள் காண்பதறிவு
Mark as Answer If you find helpful