locked
input parameter to MySQL RRS feed

  • Question

  • User-374095980 posted

    Dear All,

    I have below code that I want to make a input parameter into the SQL ?, it can be where clause or empty string. But it prompt exception???

    select * from a inner join
    (select * from b ? ) c on a.aclink=c.aclink

    Dataset.DS_CategoryReport.DT_CatItemsDataTable rDT = this.GetData(dateClause);

    ........................................................

    public virtual DS_CategoryReport.DT_CatItemsDataTable GetData(string Parameter1) {
                this.Adapter.SelectCommand = this.CommandCollection[0];
                if ((Parameter1 == null)) {
                    this.Adapter.SelectCommand.Parameters[0].Value = global::System.DBNull.Value;
                }
                else {
                    this.Adapter.SelectCommand.Parameters[0].Value = ((string)(Parameter1));
                }
                DS_CategoryReport.DT_CatItemsDataTable dataTable = new DS_CategoryReport.DT_CatItemsDataTable();
                this.Adapter.Fill(dataTable);
                return dataTable;
            }
    ..............................................................................

    select * from a inner join
    (select * from b ? ) c on a.aclink=c.aclink


    ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.42-community]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' where b.start_datetime between \'2011.04.01.00.00.00\' and \'2011.04.11.23.59' at line 8

    Monday, April 11, 2011 4:06 AM

Answers

  • User761909039 posted

    I assume you want pass a parameter to the whereclause.. if so, check out the code below

     

    public virtual DS_CategoryReport.DT_CatItemsDataTable GetData(string Parameter1) {
                SqlCommand command = new SqlCommand("SELECT * FROM a INNER JOIN " +
            "(SELECT * FROM b WHERE filterColumn = @param) c on a.aclink=c.aclink", connection) ; //Specify you filtercolumn in the whereclause 
    
        command.Parameters.Add("@param", SqlDbType.NVarChar, 15); //set your filter column datatype
    
       this.Adapter.SelectCommand = command;
    
                DS_CategoryReport.DT_CatItemsDataTable dataTable = new DS_CategoryReport.DT_CatItemsDataTable();
                this.Adapter.Fill(dataTable);
                return dataTable;
            }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 11, 2011 5:38 AM