Override

Morpheus

Regular
Joined
Jan 18, 2002
Messages
62
I have a method for searching a db:


C#:
public virtual ArrayList Search(string parameter, string columnName)
{	
			
	ArrayList al = new ArrayList();

	myCommand = MyConnection.CreateCommand();
	myCommand.CommandText = "SELECT * FROM Customer WHERE" +columnName+ "= '" + parameter + "'";
			
	myReader = myCommand.ExecuteReader();

	while(myReader.Read())
	{
		al.Add(myReader);	
	}

	return al;
}

How can I use the override to just change the connectionstring?
 
Where is the connection string defined?
You would probably be better off making the connection string a property of the class rather than using an override in this way.
 
Sorry I meant the SQL-statement.

That class is a base class for GetCustomers and GetSuppliers thought it would be the most logical way to handle requests for customers and suppliers.

But maybe its better to handle both customers and suppliers in the same class?
 
If they could both be handled in the same class then that could be a cleaner solution.
An alternative approach could be to define an interface for the Search method etc and have both the customers and suppliers classes implement it. Each would then have it's own code internal to the class but would expose a common interface for other functions to work with.
 
Back
Top