I'm working with VB2010 C# and CR13. I've created a report with empty parameter fields that I'll fill during runtime using the texts that the user will enter on multiple text boxes. I've created a dictionary that contains the parameter name as the key and the text as value.
Dictionary<String, String> textos = new Dictionary<string, string>();
textos.Add("prueba1", textBox1.Text);
textos.Add("prueba2", textBox2.Text);
textos.Add("prueba3", textBox3.Text);
textos.Add("prueba4", textBox4.Text);
textos.Add("prueba5", textBox5.Text);
textos.Add("prueba6", textBox6.Text);
textos.Add("prueba7", textBox7.Text);
textos.Add("prueba8", textBox8.Text);
Then I add the value to the report using this:
public void addValues()
{
String text;
String parameter;
foreach (KeyValuePair<String, String> t in textos)
{
text = t.Value;
parameter = t.Key;
if (!String.IsNullOrEmpty(text))
cryRpt.SetParameterValue(parameter, text);
}
}
The cryRpt.SetParameterValue(parameter, text);
gives me a COMException(HRESULT: 0x8002000B (DISP_E_BADINDEX)) which I know it's suposed to mean that the parameter name I've introduced is not the same as the parameter name in the report. The problem is that it IS the same since I've copied and pasted it to be sure.
Upon further testing I've discovered that if I cange the parameter name form prueba1 to just prueba it works. So I thought that this happened because the name of the parameter field can't have numbers on it, so I've changed all the names (for example instead of prueba2, test) and this gives me again the same Invalid index excepcion as before.
What is happening?
edit
Allright after a lot of testing I realized that I was doing it ok, the problem was with the parameter fields. Instead of creating various parameter fields I was using the same one each time. Sorry And thanks a lot to everyone.
Try this way:
List<string> s = new List<string>();
foreach (KeyValuePair<String, String> t in textos)
{
text = t.Value;
s.Add(text);
}
Then in a new loop like this:
for (int i = 0; i < s.Count; i++)
{
cryRpt.SetParameterValue(i, s[i]);
}
And what do you mean about empty parameter fields?
User contributions licensed under CC BY-SA 3.0