I'm developing a web app using Asp.net webforms. The requirement is to populate a gridview based on selected value from dropdown which I can achieve no problem. What I'm trying to do is minimize my code so I don't have to repeat myself. So I've created a method which returns a DataTable
from the query that is passed in as a parameter to that function.
public DataTable GetData(string Query)
{
//Do stuff i.e. sql reader
...
}
Some of the Sql quesries will have params and others won't e.g.
SELECT TESTONE FROM MY TABLE WHERE TESTONE = @param
SELECT TESTTWO FROM MY TABLE
I want to be able to call GetData()
method with both of the above queries but I can't figure out how to extend my function to accommodate for both scenarios. If someone can guide me I would highly appreciate it.
Would using a GetData(string Query, Dictionary<string, object> parameters)
be a overkill in this case?