An explanation may be in order as well.
ParametersRequiredForCommandExecution is a ReportingDBDataParameterCollection
containing all those parameters wither parsed out of a query string or from a
Stored Procedure.
You can see in the code below that I parse CommandText (for CommandType.Text
commands) and call a SPROC I wrote to return the parameters required by a
given stored procedure.
internal ReportingDBDataParameterCollection
ParametersRequiredForCommandExecution
{
get
{
if (parametersRequiredForCommandExecution == null)
{
parametersRequiredForCommandExecution = new
ReportingDBDataParameterCollection();
if (this.commandType == CommandType.Text)
{
//Process for CommandType.Text
int indexOf = 0;
int startIndex = 0;
indexOf = commandText.IndexOf("@", startIndex);
while (indexOf != -1)
{
string s = commandText.Substring(indexOf);
string[] tokens = s.Split(new char[] {' '});
parametersRequiredForCommandExecution.Add(new
ReportingDBDataParameter(tokens[0], null));
startIndex = indexOf + 1;
indexOf = commandText.IndexOf("@", startIndex);
}
}
else
{
//Process for CommandType.StoredProcedure
if (commandText.Trim() != string.Empty)
{
//Extract the stored procedure name from commandText (assume first
token is SPROC name)
string[] tokens = commandText.Split(new char[] {' '});
string storedProcedureName = tokens[0];
//Establish a connection to a 'template' database (any instance of a
target DB that we can always
//be sure is present) to try to get the SPROC's parameters from.
Note we cannot go to the specific
//target at this point becuase we have not had an opportunity to
gather any runtime information (which,
//through the MemberID would tell us the specific database to go to).
TemplateReportingDB templateReportingDB = new TemplateReportingDB();
SqlConnection connection = new
SqlConnection(templateReportingDB.ConnectionString);
connection.Open();
//Set up a command object
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = "spRPT_StoredProcedureParameters";
command.Parameters.Add("@StoredProcedureName", storedProcedureName);
//Go get the paramters using the SPROC specified above
SqlDataReader reader = command.ExecuteReader();
//See what we got back
int targetColumn;
if (reader.HasRows)
{
targetColumn = reader.GetOrdinal("PARAMETER_NAME");
}
else
{
throw new Exception("Stored procedure " + storedProcedureName + "
was not found in the target database.");
}
while (reader.Read())
{
parametersRequiredForCommandExecution.Add(new
ReportingDBDataParameter(reader.GetString(targetColumn), null));
}
connection.Close();
}
}
}
return parametersRequiredForCommandExecution;
}
}
[quoted text, click to view] "Dan" wrote:
> Sorry, the group took so long to refresh i thought it wasn't working (and i
> submitted it 3 times grrrrr)
>
> "Dan" wrote:
>
> > Has anyone implemented this interface?
> >
> > If so would you be willing to share your code?
> >