ねえ、私は現在私のコードにこのメソッドを持っています:
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接続とアダプターを含めるのは良いアプローチですか?そうでない場合、それをどのようにリファクタリングできますか?どういうわけか、これはたとえばテストには適していないと思います...
あなたのアイデアをありがとう:)