-3

We are creating the site in Visual Studio 2010 using C# and ASP.Net webforms. We have no idea why its broke and gone wrong followed an online tutorial and after fixing other problems the code had this error has come up and i dont know how to fix it or what i have done wrong if anyone can see a the problem please let me know.

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

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

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

private ArrayList GetClothesByType(string ClothesType)
{
    ArrayList list = new ArrayList();
    string query = string.Format("SELECT * FROM fusey WHERE type LIKE '{0}'", ClothesType);

    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 size = reader.GetString(4);
            string image = reader.GetString(5);
            string review = reader.GetString(6);

            Fusey fusey = new Fusey(id, name, type, price, size, image, review);
            list.Add(fusey);
        }
    }
    finally
    {
        conn.Close();
    }

    return list;
}



internal static ArrayList GetClothesByType(object ClothesType)
{
    throw new NotImplementedException();
}
}
Austin Salonen
  • 49,173
  • 15
  • 109
  • 139
James Taaffe
  • 9
  • 1
  • 1
  • 2
    At a glance I'd say this line `throw new NotImplementedException()` in your `GetClothesByType` method is why you're seeing the exception...try putting some code in there. – Tim Apr 24 '13 at 17:58
  • http://www.catb.org/esr/faqs/smart-questions.html#urgent – Austin Salonen Apr 24 '13 at 18:01

2 Answers2

2

You're getting a Not Implemented Exception? Thats because it's not implemented.

internal static ArrayList GetClothesByType(object ClothesType)
{
    throw new NotImplementedException(); // you need to implement this method
}

I don't see anywhere in your code that you call this, but somewhere you are and I imagine that when you do, you get this exception.

MSDN documentation on NotImplementedException if you're interested

I also see that you have an overload for GetClothesByType -- you may be confusing a method call and passing in an object instead of a string, resulting in it calling the wrong, unimplemented, method.

Could you please show us your code where you are calling GetClothesByType?

tnw
  • 13,521
  • 15
  • 70
  • 111
2

I think that you are wrongly calling the static method instead of the private one.
If your intention is to call the method that takes a string as input parameter then you need to declare it public and create an instance of the class ConnectionClass

ConnectionClass cs = new ConnectionClass(....);
ArrayList clothes = cs.GetClothesByType("t-shirt");

However let me point that storing a connection in that way is a bad practice.
The DbConnection is a precious resource and should be used when needed and immediately released. Moreover, never take for granted what your user types at the keyboard and pass that blindly to the database engine.
You open the way to Sql Injection Attacks, use always parametrized queries

public ArrayList GetClothesByType(string ClothesType)
{
    ArrayList list = new ArrayList();

    string query = "SELECT * FROM fusey WHERE type LIKE @ctype";
    string connectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString();
    using(SqlConnection conn = new SqlConnection(connectionString))
    using(SqlCommand command = new SqlCommand(query, conn))
    { 
       command.Parameters.AddWithValue("@ctype", ClothesType);
       conn.Open();
       SqlDataReader reader = command.ExecuteReader();
       .....
    }
}
Community
  • 1
  • 1
Steve
  • 213,761
  • 22
  • 232
  • 286