Hi all.
Does anyone know how I can define a method that can return both a DataTable and a int or string?
I've tried this:
Code:
internal interface IQuery
{
void OpenConnection();
void CloseConnection();
T DoQuery<T>();
}
abstract internal class QueryClass : IQuery
{
...
public abstract T DoQuery<T>();
}
class OpenQuery : QueryClass
{
public override T DoQuery<T>()
{
DataTable dt = new DataTable();
try
{
try
{
this.OpenConnection();
dt.Load(Command.ExecuteReader());
return dt;
...
}
}
}
}
...
OpenQuery query = new OpenQuery(queryname, parameters);
return query.DoQuery<DataTable>();
Obviously I can't return a DataTable when the return type is not defined in the DoQuery method and I can't call Load on a generic type. How do you guys work around this??
- mega
Moving to C# .NET