現在、すべてのデータベース接続を処理する接続クラスがあります。私がやろうとしているのは、1つのページにSqlParameterCollectionオブジェクトを作成し、そのオブジェクトを接続クラスに渡すことです。これを行うことは可能ですか?コンパイルエラーは発生しませんが、認識されるパラメータを取得できません。これが私がやろうとしていることです:
Page 1:
string sql = null;
conn.strConn = connectionstring;
sql = "sqlstring";
SqlParameterCollection newcollect = null;
newcollect.Add("@Switch",1);
conn.OpenReader(sql, newcollect);
while (conn.DR.Read())
{
read data onto page here...
}
conn.CloseReader();
Page 2 (connection class) :
public void OpenReader(string sql, SqlParameterCollection collect)
{
Conn = new SqlConnection(strConn);
Conn.Open();
Command = new SqlCommand(sql,Conn);
Command.Parameters.Add(collect); <------This is the root of my question
Command.CommandTimeout = 300;
// executes sql and fills data reader with data
DR = Command.ExecuteReader();
}