How to pass custom sql command to fastreport.net via application using C #?

I'm starting to use fastreport.net to create a report in C #, since Crystal reports are not compatible with .net4. It is so simple, but it is so difficult. I am trying to pass the sql command to my report through my application, but it does not work. Can someone help me? Here is the code:

Report rpt = new Report(); rpt.Load("H:\\MyReport.frx"); rpt.SetParameterValue("Parameter", "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Confictionary"); FastReport.Data.TableDataSource data = rpt.GetDataSource("Contact") as FastReport.Data.TableDataSource; data.SelectCommand = "SELECT * from contact"; rpt.Prepare(); rpt.ShowPrepared(); 

It throws an exception on line 5: "The reference to the object is not installed in the instance of the object." Please help me. tnx a lot

+4
source share
1 answer

I think that the SQL command should be in the report template, and not dynamically, unless it is used only to create the report file.

i use this:

  FReport.SetParameterValue("SQL_rysys", ConnectionString); if (FReport.Dictionary.Connections.Count > 0) { FReport.Dictionary.Connections[0].ConnectionString = ConnectionString; FReport.Dictionary.Connections[0].ConnectionStringExpression = "[SQL_rysys]"; FReport.Dictionary.Connections[0].CommandTimeout = 60; } 

This code assigns a value to the parameter "SQL_rysys" (SQL_connection in English), I pass the SQL connection string. Also, if there are any connections in the data dictionary, I assign the connection string to the first.

This way, my reports always get the correct connection string, but the SQL query is already included in the report. The reason is that there is no other way to create a report in the designer without using a query to retrieve data, and this query is saved in the XML report file (frx).

I asked fastreport support how to assign a request, but their AWFUL and noobs support work there.

+2
source

All Articles