How to use SQL Query Parameter?
Hi all
I need some help about using SQL Query Parameter in reports.
When i m trying to use this code "select * from some_table where id=@param1" gives a error like in the image.
I need some help about using SQL Query Parameter in reports.
When i m trying to use this code "select * from some_table where id=@param1" gives a error like in the image.
Comments
Please read the user's manual:
http://fast-report.com/documentation/UserM...yparameters.htm
select * from table where field in (@param1, @param2)
- add a new parameter;
- set up its properties (Name, DataType, DefaultValue, Expression).
How can i buid a report befor run let the user choose select from a list or textbox predefined parameter.
http://fast-report.com/documentation/UserM...passvalueto.htm
If you want to form a SQL text dynamically, use the following code:
TableDataSource table = Report.GetDataSource("MyTable") as TableDataSource;
table.SelectCommand = your_sql_text;
Text1.TextBox.AutoCompleteMode = ...;
Text1.TextBox.AutoCompleteSource = ...;
(see more details here: http://fast-report.com/documentation/UserM...ingcontrol.htm)
I ask so many questions but how can i pass DataSelectorControl value to paramater?
http://www.fast-report.com/en/forum/?p=/discussion/5690
TableDataSource Table = Report.GetDataSource("Connection") as TableDataSource;
Table.SelectCommand = "select * from fason where firma in (" + @P1 + ")";
(where P1 is the string-type variable)
FastReport.Net v1.3.8
Failed to convert parameter value from a DataSelectorControl to a String.
Inner exception:
Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType)
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType)
at System.Data.SqlClient.SqlParameter.GetCoercedValue()
at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
at System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters)
at System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc)
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 FastReport.Data.DataConnectionBase.FillTableData(DataTable table, String selectCommand, CommandParameterCollection parameters)
at FastReport.Data.DataConnectionBase.FillTable(TableDataSource source)
at FastReport.Data.TableDataSource.LoadData(ArrayList rows)
at FastReport.Data.DataSourceBase.Init(Relation relation, String filter, SortCollection sort)
at FastReport.Data.DataSourceBase.Init(DataSourceBase parentData, String filter, SortCollection sort)
at FastReport.Data.DataSourceBase.Init(DataSourceBase parentData)
at FastReport.Dialog.DataFilterBaseControl.FillData(DataSourceBase parentData)
at FastReport.Dialog.DataFilterBaseControl.InitializeControl()
at FastReport.Dialog.DialogPage.l1rVOO3Rq()
at FastReport.Engine.ReportEngine.mdGv397RC(DialogPage )
at FastReport.Engine.ReportEngine.j2uIoT5PW()
at FastReport.Engine.ReportEngine.sIBSXiMcT(Boolean , Boolean , ReportPage )
at FastReport.Report.Prepare(Boolean append)
at FastReport.Report.Prepare()
at AxMUPd3GmP2LsD21tJe.HDAvfI3ulEnI6JrqKyR.5AG75Lqn0()
Here is the corrected report. I'm not sure if it will work because I have no database and can't check it.
The Test file only for "Test" i want to make realy realy complex reports using views,relational tables can you modify my report passing multi values to sql parameter.
FastReport.Net v1.3.8
Failed to convert parameter value from a DataSelectorControl to a String.
Inner exception:
Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType)
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType)
at System.Data.SqlClient.SqlParameter.GetCoercedValue()
at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
at System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters)
at System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc)
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 FastReport.Data.DataConnectionBase.FillTableData(DataTable table, String selectCommand, CommandParameterCollection parameters)
at FastReport.Data.DataConnectionBase.FillTable(TableDataSource source)
at FastReport.Data.TableDataSource.LoadData(ArrayList rows)
at FastReport.Data.DataSourceBase.Init(Relation relation, String filter, SortCollection sort)
at FastReport.Data.DataSourceBase.Init(DataSourceBase parentData, String filter, SortCollection sort)
at FastReport.DataBand.InitDataSource()
at FastReport.Engine.ReportEngine.Hoske0MJH(DataBand )
at FastReport.Engine.ReportEngine.iOYhKNX5Qq(BandCollection )
at FastReport.Engine.ReportEngine.pTShUSvp6t(ReportPage )
at FastReport.Engine.ReportEngine.vyxhMoXTvD()
at FastReport.Engine.ReportEngine.PLiKTkb6F(ReportPage )
at FastReport.Engine.ReportEngine.sIBSXiMcT(Boolean , Boolean , ReportPage )
at FastReport.Report.Prepare(Boolean append)
at FastReport.Report.Prepare()
at AxMUPd3GmP2LsD21tJe.HDAvfI3ulEnI6JrqKyR.5AG75Lqn0()
"Failed to convert parameter value from a DataSelectorControl to a String.
Inner exception:
Object must implement IConvertible."
but now;
FastReport.Net v1.3.8
Invalid column name 'ADONTE'. 'ADONTE' is my selected value not a column.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
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 FastReport.Data.DataConnectionBase.FillTableData(DataTable table, String selectCommand, CommandParameterCollection parameters)
at FastReport.Data.DataConnectionBase.FillTable(TableDataSource source)
at FastReport.Data.TableDataSource.LoadData(ArrayList rows)
at FastReport.Data.DataSourceBase.Init(Relation relation, String filter, SortCollection sort)
at FastReport.Data.DataSourceBase.Init(DataSourceBase parentData, String filter, SortCollection sort)
at FastReport.DataBand.InitDataSource()
at FastReport.Engine.ReportEngine.Hoske0MJH(DataBand )
at FastReport.Engine.ReportEngine.iOYhKNX5Qq(BandCollection )
at FastReport.Engine.ReportEngine.pTShUSvp6t(ReportPage )
at FastReport.Engine.ReportEngine.vyxhMoXTvD()
at FastReport.Engine.ReportEngine.PLiKTkb6F(ReportPage )
at FastReport.Engine.ReportEngine.sIBSXiMcT(Boolean , Boolean , ReportPage )
at FastReport.Report.Prepare(Boolean append)
at FastReport.Report.Prepare()
at AxMUPd3GmP2LsD21tJe.HDAvfI3ulEnI6JrqKyR.5AG75Lqn0()