C# 2005 - Parameterized Crystal Reports question

jcrcarmo

Active member
Joined
Dec 14, 2005
Messages
32
Hi guys,

Im trying to run a parameterized crystal report in C# (Visual Studio 2005 Professional) getting values from 3 textbox controls (windows form):

cbCliente is the textbox control for the clients name (string)
DataIni is the textbox control for the initial date (DateTime)
DataFin is the textbox control for the final date (DateTime)

The code below runs just fine, but when I try to add the DataIni and DataFin parameters, it gives an error message:

private void btnFatura_Click(object sender, EventArgs e)
{
string selectFormula = "Mid({qryALL1.Cliente}, 1) = \"" + cbCliente.Text + "\"";
crystalReportViewer1.SelectionFormula = selectFormula;
}

My question is: How do I add the DataIni and DataFin parameters? Ive tried many ways, but they didnt work. Im getting the synthax wrong somewhere:

string selectFormula = "Mid({qryALL1.Cliente}, 1) = " + cbCliente.Text + " AND {qryALL1.Date} in (" + Convert.ToDateTime(DataIni.Text) + ") to (" + Convert.ToDateTime(DataFin.Text) + ")";

Thanks in advance,

JC :)
 
Last edited by a moderator:
Hi,

First, i think you have an error of syntax in MID() function, MID function gets 3 parameters and you just gave it 2, you should rewrite it as Mid({qryALL1.Cliente}, 1,<number of characters you want to get>)
And besides it try to use the DateTime.Parse(string) inspite of ConverttoDateTime(), I have already been in trouble with the dates, because there is a lot of datetime format details

If this not work, try to use as i usually do, inspite of using SQL Querys inside the reports directly for data fill, you use a sql query just for get the fields name (just structure) and after that at runtime you pass a datatable to the report and it retrives the data, this can be usefull because datatable object allows you to make a lot of work in the hood as filtering,sorting, etc and for example for you case in specific, you could filter your data with an DataView object inspite of using direcly formulas, who know it can be a nice alternative.

Other thing is i dont know wich of these ideas i gave you are the most performant, by logic maybe using a datatable to bind to your report should get more memory consume, but im not able to grant this.

I hope this can help you in something.

Rgds
Tiago Teixeira
 
Back
Top