2013-04-24 2 views
-3

C# 및 ASP.Net 웹 폼을 사용하여 Visual Studio 2010에서 사이트를 만들고 있습니다. 우리는 왜 그것의 부러 졌는지 잘못 알고 온라인 튜토리얼을 따라 갔다가 다른 문제를 고친 후에 코드에이 오류가 발생했습니다. 그 문제를 해결하는 방법이나 다른 사람들이 문제를 볼 수 있다면 무엇을했는지 알지 못합니다. 나도 알아.사용자 코드에 의해 처리되지 않은 NotImplementedException

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(); 
} 
} 
+2

은'당신'GetClothesByType' 방법에 ... 거기에 코드를 넣으십시오. – Tim

+0

http://www.catb.org/esr/faqs/smart-questions.html#urgent –

답변

2

구현되지 않은 예외가 발생합니까? 그게 이 아니기 때문에이 구현되었습니다.

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

난 당신이 전화를 당신의 코드에서 어디서든 볼 수 없지만, 어딘가에 당신이 내가 당신이 할 경우, 당신은이 예외를 얻을 상상.

MSDN documentation on NotImplementedException 당신이 관심이 있다면

나는 또한 당신이 GetClothesByType에 대한 과부하를 볼

- 잘못된 호출 그 결과, 메서드 호출을 혼동하고 대신 stringobject 전달 할 수있다, 구현되지 않은 메소드.

코드를 GetClothesByType으로 보내 주시겠습니까?

2

나는 당신이 잘못 개인 메서드 대신 정적 메서드를 호출하는 것 같아요. 당신의 의도는 다음이 공개 선언하고 클래스의 인스턴스를 만들 필요가 입력 매개 변수로 문자열을 사용하는 방법을 호출하는 경우
ConnectionClass

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

그러나 내가 그런 식의 연결을 저장하는 것을 지적하자 나쁜 습관입니다.
DbConnection은 중요한 리소스이므로 필요한 경우 즉시 사용하고 사용해야합니다. 또한 사용자가 키보드에서 입력하는 것을 당연하게 생각하지 말고 데이터베이스 엔진에 맹목적으로 전달하십시오. 당신이 예외를보고하는 이유
당신은 Sql Injection 공격에 길을 열어 사용 항상 매개 변수화 된 쿼리 나는이 라인은`새로운 NotImplementedException()를 던져 말하고 싶지만 눈에

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(); 
     ..... 
    } 
} 
+0

훨씬 더 유용한 답변입니다. –

관련 문제