嘿,我目前在我的代码中有这个方法:
public static DataSet PrepareDataSet(some params)
{
SqlConnection sqlConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlDataAdapter adapter = new SqlDataAdapter(Utils.EscapeProcedureName(...), sqlConnection);
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
//do some stuff with the adapter using the params
sqlConnection.Open();
DataSet dataSet= new DataSet();
adapter.Fill(dataSet);
sqlConnection.Close();
return dataSet;
}
此代码是从 aspx.cs 页面调用的。在方法中包含 SQL 连接内容和适配器是一种好方法吗?如果不是,那如何重构?不知何故,我认为这不利于测试,例如......
谢谢你的想法:)