【发布时间】:2019-06-12 13:57:58
【问题描述】:
我有两种返回类型化数据集的方法。 我希望只有一种通用方法。
private TypedDataSet GetData(string query, string tblName)
{
string conString = .... ;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (TypedDataSet tds = new TypedDataSet ())
{
sda.Fill(tds , tblName);
return tds ;
}
}
}
}
【问题讨论】:
-
这里需要通用什么?
-
返回值需要通用
-
我只看到一个返回类型,即
TypedDataset。除此之外请注意,在方法中返回该实例后,您将使用using处理它,因此您无法使用它。 -
你的意思是
private T GetData<T>(string query, string tblName) where T : DataSet, new()?很久没有求助于这些物品了。 -
我们需要更多信息。我们需要知道您的型号。我们需要知道您为什么要在其中使用泛型。