• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

app_code method cannot be access

I try to use the methods class from app_code, by using
Item.Methods.PurchaseItem
but failed
then i try to remove the namespace in methods.cs, also failed.

also notice that the DataSet , SqlDataAdapter in App_Code do not change colour.
Methods.cs (App_Code)
--------------------
namespace Item
{

    public class Methods
    {

        public Methods()
        {

        }

        private static string connstring = "Data Source=123\\SQLEXPRESS;Initial Catalog=productdb;User Id=xx;Password=xxx;";

        #region PurchaseItem

        public static string PurchaseItem(string itemname, int quantity, DateTime dt)
        {
            using (SqlConnection sqlconn = new SqlConnection(connstring))
            {

                DataSet dsItem = new DataSet();

                string strSQL = "Select * from Item where ItemName = '" + itemname + "'";
                SqlDataAdapter adapter = new SqlDataAdapter(strSQL, sqlconn);
                adapter.Fill(dsItem);

Open in new window

0
doramail05
Asked:
doramail05
  • 6
  • 4
1 Solution
 
Albert Van HalenAnalyst developerCommented:
Make your class static : public static class Methods.
You can loose the default constructor ( public Methods() {} )
0
 
doramail05Author Commented:
i switched to WebSite template instead of WebApplication,
the colour of DataSet, SqlDataAdapter changed,
but still cannot access App_Code methods.
0
 
TeazerMDCommented:
Try adding this next to the rest of the usings:
using Item;

If this dosen't help - what does Intellisense tell you? Does it see this Namespace->Class->Method?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
doramail05Author Commented:
AlbertVanHalen & TeazerMD:

tried but cannot
0
 
doramail05Author Commented:
Intellisense sense here :

namespace Item
{
    public partial class Purchase : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Item.Purchase < --
        }
    }
}
0
 
TeazerMDCommented:
protected  void Page_Load(object sender, EventArgs e)
        {
            Methods.PurchaseItem(...);
        }
0
 
doramail05Author Commented:
yea,
that is what im trying to achieve,

could not find Methods in intellisense totally.
0
 
TeazerMDCommented:
Too bad.
I can help you further only if you are willing to supply the source project.
0
 
doramail05Author Commented:
theres an error trying to upload project file with .aspx extension, so i removed them, you can add them back easily.
Methods.cs (App_Code)
----------
public class Methods
    {

        public Methods()
        {

        }
        ...

Purchase.aspx.cs
----------------
public partial class Purchase : System.Web.UI.Page
{
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
}

Open in new window

WebSite2.zip
0
 
TeazerMDCommented:
Ok, your problem is that the "Methods.cs" is located in the App_Data instead of App_Code.
0
 
doramail05Author Commented:
o.O !  
ok thanx for that.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now