mrt based query with parameters

Stimulsoft Reports.NET discussion
Post Reply
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

mrt based query with parameters

Post by brianj774 »

In the standalone designer I open an mrt fiile containing a connection to a sql database, with a query :

Code: Select all

select * from tblStatement where ID = @prmStatementID
When the query runs as a test, it works fine, but when the report is previewed, it reports the following error:

Code: Select all

----------------------------
[General Info]

Application: Stimulsoft Reports.Net
Framework:   v4.0.30319
Version:     Version: 2012.1.1300 from 3 April 2012
MachineName: TANGERINE2
OSVersion:   Microsoft Windows NT 6.1.7601 Service Pack 1
UserName:    brian

----------------------------
[Exception Info]
Message:     The parameterized query '(@prmStatementID int)select * from tblStatement where ID = @prmS' expects the parameter '@prmStatementID', which was not supplied.
Statement(s) could not be prepared.

Source:      .Net SqlClient Data Provider

StackTrace:
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   at Stimulsoft.Report.Dictionary.StiSqlSource.UpdateParameters()
   at Stimulsoft.Report.Dictionary.StiSqlAdapterService.ConnectDataSourceToData(StiDictionary dictionary, StiDataSource dataSource, Boolean loadData)
   at Stimulsoft.Report.Dictionary.StiDataSource.Connect(StiDataCollection datas, Boolean loadData)
   at Stimulsoft.Report.Dictionary.StiDataSourcesCollection.Connect(StiDataCollection datas, Boolean loadData)
   at Stimulsoft.Report.Dictionary.StiDictionary.Connect(Boolean loadData)
   at Stimulsoft.Report.Engine.StiRenderProviderV2.ConnectToData(StiReport report)
   at Stimulsoft.Report.Engine.StiRenderProviderV2.Render(StiReport report, StiRenderState state)
   at Stimulsoft.Report.Engine.StiReportV2Builder.RenderSingleReport(StiReport masterReport, StiRenderState renderState)
   at Stimulsoft.Report.StiReport.RenderReport(StiRenderState renderState)
   at Stimulsoft.Report.StiReport.Render(StiRenderState renderState, StiGuiMode guiMode)
   at Stimulsoft.Report.Design.Controls.StiDesignerPreviewControl.btRefresh_Click(Object sender, EventArgs e)

----------------------------
[Assemblies]
mscorlib, Version = 2.0.0.0
Stimulsoft.Base, Version = 2012.1.1300.0
Stimulsoft.Report, Version = 2012.1.1300.0
Stimulsoft.Report.Design, Version = 2012.1.1300.0
System.Windows.Forms, Version = 2.0.0.0

If I provide an "expression" value to the Parameter 'object', this error goes away. Is that expected behavior.

However, if I then attempt from the C# code to apply the parameter:

Code: Select all

report["prmStatementID"] = 17745;
The change does not propogate to override that value I set in the expression (above).

Can you explain what I'm doing wrong...? How can I create an mrt that works in both the standalone designer, AND called from csharp ?

Thanks.
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

mrt based query with parameters

Post by brianj774 »

thanks to this post (( http://forum.stimulsoft.com/Default.aspx?g=posts&t=6086 )) .. I found my answer...or at least one that seems to get me there.

If I change my c# code to apply the parameter as such...

Code: Select all

            // Set some report parameters
            report.DataSources["DataGet"].Parameters["prmStatementID"].Value = id.ToString();
            report.DataSources["DataGet"].Parameters["prmStatementID"].ParameterValue = id;
then everything seems to work just fine. Setting JUST the ParameterValue as in the linked URL above did NOT work, but when I also changed the Value property, then it all clicked together nicely.

Any issues with this solution, Stimulsoft?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

mrt based query with parameters

Post by HighAley »

Hello.

Did you try to use this code before compilation?

Code: Select all

report["prmStatementID"] = 17745;
If yes, then it's wrong.
Before compiling yo should set

Code: Select all

report.DataSources["DataGet"].Parameters["prmStatementID"].Value
Thank you.
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

mrt based query with parameters

Post by brianj774 »

I am not compiling at all.

Should I be? Whats the benefit? My report SEEMS to be working fine ....
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

mrt based query with parameters

Post by Alex K. »

Hello,

Ok.
Let us know if you need any additional help.
rumblecow
Posts: 33
Joined: Fri Nov 08, 2013 3:47 pm

Re: mrt based query with parameters

Post by rumblecow »

brianj774 wrote:I am not compiling at all.

Should I be? Whats the benefit? My report SEEMS to be working fine ....
Did you ever get an answer on compiling?
rumblecow
Posts: 33
Joined: Fri Nov 08, 2013 3:47 pm

Re: mrt based query with parameters

Post by rumblecow »

brianj774 wrote:I am not compiling at all.

Should I be? Whats the benefit? My report SEEMS to be working fine ....
The data in my report appears to be correct using the report["FromDate"] = new DateTime(2010,10,1); syntax but the parameter values which are shown in the report header don't reflect the value used.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: mrt based query with parameters

Post by Alex K. »

Hello,

Please try to use the following code:

Code: Select all

report.Dictionary.DataSources["Name"].Parameters["FromDate"].Value = "\"10/1/2010\"";
Thank you.
Post Reply