Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi guys,

 

I'm 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 client's 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? I've tried many ways, but they didn't work. I'm 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 :)

Edited by jcrcarmo
  • 2 weeks later...
Posted

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 don't 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 i'm not able to grant this.

 

I hope this can help you in something.

 

Rgds

Tiago Teixeira

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...