Passing a custom sql command

Magezi SagesseMagezi Sagesse DRCONGO
edited 6:06PM in FastReport .NET
I have a problem with passing a custom sql command, I don't know how to pass parameters to tabledatasource selectcommand as it can be done with oledbcommand.parameters.add(.....), working without that is handling error when I the where condition data has an apostrophy.

Example: table.selectcommand="select * from listetous where objsup='l'homme'" with oledbcommand it works when I use parameter :
oledbcommand.commandtext= ="select * from listetous where objsup=a"
oledbcommand.parameters.add("a",oledbvarchar,255).value= "l'homme"

Can someone help me showing me how to use parameters with tabledatasource?

thank you!!!

Comments

  • Magezi SagesseMagezi Sagesse DRCONGO
    edited 6:06PM
    I have a problem with passing a custom sql command, I don't know how to pass parameters to tabledatasource selectcommand as it can be done with oledbcommand.parameters.add(.....), working without that is handling error when I the where condition data has an apostrophy.

    Example: table.selectcommand="select * from listetous where objsup='l'homme'" with oledbcommand it works when I use parameter :
    oledbcommand.commandtext= ="select * from listetous where objsup=a"
    oledbcommand.parameters.add("a",oledbvarchar,255).value= "l'homme"

    Can someone help me showing me how to use parameters with tabledatasource?

    thank you!!!

    I have gotten the solution :

    what I did was to declare a fastreport commandparameter, I passed the value to that parameter and added the parameter to the tabledatasource paramtercollection


    'Declaration of the parameter
    dim p as new fastreport.commandparameter
    'name of the parameter
    p.name=a
    'parameter data type 
    p.datatype = oledb.datatype.varchar
    'passing a value to the parameter
    p.value ="l'homme"
    'defining the size of data
    p.size =50
    
    table.parameters.add(p)
    
  • edited 6:06PM
    using FastReport.Data;

    report1.Load("report1.frx");
    TableDataSource table = report1.GetDataSource("Table1") as TableDataSource;
    table.SelectCommand = "SELECT * FROM CUSTOMERS";
    report1.Show();

Leave a Comment