For the system I am creating which is a report generator, there is a form which is created based on the parameters required for a stored procedure, the code for this is:
for (int i = 0; i < datatable.Rows.Count; i++)
{
string label = datatable.Rows[i]["label"].ToString();
Label mylabel = new Label();
mylabel.Text = label + ":";
reportParametersPlaceHolder.Controls.Add(mylabel);
if (datatable.Rows[i]["data_type"].ToString() == "datetime")
{
TextBox myTextBox = new TextBox();
myTextBox.CssClass = "form-control";
myTextBox.TextMode = TextBoxMode.Date;
reportParametersPlaceHolder.Controls.Add(myTextBox);
}
else
{
TextBox txtBox = new TextBox();
txtBox.CssClass = "form-control";
reportParametersPlaceHolder.Controls.Add(txtBox);
}
}
I then have a button which when selected should display a gridview with the results from the stored procedure. The problem I'm having is, because the website is dynamic - meaning it can work for any report without new pages being added and with the way the input fields are being generated how can I insert the parameters into the stored procedure when the number of parameters differs for each. the code for inserting into a stored procedure is:
SqlCommand command = new SqlCommand(reportName);
command.Parameters.AddWithValue("@auth_name", authName);
command.Parameters.Add(new SqlParameter()
{
ParameterName = "RETURN_VALUE",
Direction = ParameterDirection.ReturnValue
});
SqlCommand command = new SqlCommand(reportName);
command.Parameters.AddWithValue("@param", param);
command.Parameters.Add(new SqlParameter()
{
ParameterName = "RETURN_VALUE",
Direction = ParameterDirection.ReturnValue
});
Thanks in advance