I have hese two classes which are not in the same folder. Coffee.aspx.cs is in folder named Pages and the other class ConnectionClass.cs is in other folder named App_data

can anybody help me to correct the code i ma having the errors
see the code:

i am getting these errors from Coffe aspx.cs:
1.(The name 'ConnectionClass' does not exist in the current context)

I am getting these errors in ConnectionClass.cs

2.(The type or namespace name 'ArrayList' could not be found (are you missing a using directive or an assembly reference?)
3.(The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)
4.(The type or namespace name 'Coffee' could not be found (are you missing a using directive or an assembly reference?)

Coffe.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;




namespace WebApplication4
{
    public partial class Coffee : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            FillPage();
        }
        private void FillPage()
        {
            ArrayList coffeeList = new ArrayList();

            if (!IsPostBack)
            {
                coffeeList = ConnectionClass.GetCoffeeByType("%");
            }
            else
            {
                coffeeList = ConnectionClass.GetCoffeeByType(DropDownList1.SelectedValue);
            }

            StringBuilder sb = new StringBuilder();

            foreach (Coffee coffee in coffeeList)
            {
                sb.Append(string.Format(@"<table class='coffeTable'
                  <tr>
                    <th rowspan ='6' width='150px'><img runat='server' src={6}/></th>
                    <td width='50px'>Name</td>   
                  </tr>

                  <tr>
                    <th>Type</th>
                    <td>{1}</td>   
                  </tr

                  <tr>
                    <th>Price</th>
                    <td>{2} $</td>   
                  </tr
                 <tr>
                    <th>Roast</th>
                    <td>{}</td>   
                  </tr
                   <tr>
                    <th>Origin</th>
                    <td>{4}</td>   
                  </tr>

                  <tr>
                        <td colspan='2'>{5}</td>
                  </tr>


                </table>",
                        coffee.name, coffee.type, coffee.price, coffe.roast, coffee.roast, coffee.country, coffee.review, coffee.image));
            }
            lblOutput.Text = sb.ToString();
        }
        protected void DropDownList_SelectedIndexChange(object sender, EventArgs e)
        {
            FillPage();
        }
    }
}

ConnectionClass.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;


public static class ConnectionClass
{
    private static SqlConnection conn;
    private static SqlCommand command;

    static ConnectionClass()
    {
        string connectionString = ConfigurationManager.ConnectionStrings["coffeeConnection"].ToString();
        conn = new SqlConnection(connectionString);
    }

    public static class ConnectionClass
    {
        private static SqlConnection conn;
        private static SqlCommand command;

        static ConnectionClass()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["coffeeConnection"].ToString();
            conn = new SqlConnection(connectionString);
            command = new SqlCommand("", conn);
        }

        public static ArrayList GetCoffeeByType(string coffeeType)
        {
            ArrayList list = new ArrayList();
            string query = string.Format("SELECT * FROM coffee WHERE type LIKE '{0}'", coffeeType);

            try
            {
                conn.Open();
                command.CommandText = query;
                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    int id = reader.GetInt32(0);
                    string name = reader.GetString(1);
                    string type = reader.GetString(2);
                    double price = reader.GetDouble(3);
                    string roast = reader.GetString(4);
                    string country = reader.GetString(5);
                    string image = reader.GetString(6);
                    string review = reader.GetString(7);

                    Coffee coffee = new Coffee(id, name, type, price, roast, country, image, review);
                    list.Add(coffee);
                }
            }
            finally
            {
                conn.Close();
            }

            return list;
        }

    }
}
Member Avatar for LastMitch

@Kleon

can anybody help me to correct the code i ma having the errors

How can you not set-up your files correctly on MVC framework?

You need to place the path to each file.

The reason why the error comes up because you didn't do your job placing the files. It's not reading it because it doesn't exists.

Do you have a file that contain those code?

You should have a file somewhere in your MVC framework.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.