How to use SQL Query Parameter?

2»

Comments

  • edited 7:44PM
    The sended query "select * from fason where firma in ("EUROTEX", "GAPSAN", "RNC")" with (") doubles can you change code to (').
  • edited 7:44PM
    You can change the report script code by yourself.
  • edited 7:44PM
    I tryed but no succes can you tell me what must i do.

    private void btnOk_Click(object sender, EventArgs e)
    {
    DataSelector1.FilterData();
    TableDataSource table = Report.GetDataSource("Table1") as TableDataSource;
    table.Init();

    // selectedItems will contain a list of selected items, like "Item1", "Item2", "Item3"
    string selectedItems = "";
    table.First();

    while (table.HasMoreRows)
    {
    selectedItems += "\"" + table["firma"].ToString() + "\", ";
    table.Next();
    }
    if (selectedItems.EndsWith(", "))
    selectedItems = selectedItems.Remove(selectedItems.Length - 2);

    // now change the sql text of the Table datasource
    table = Report.GetDataSource("Table") as TableDataSource;
    table.SelectCommand = "select * from fason where firma in (" + selectedItems + ")";
  • edited 7:44PM
    If you need single quotes, change the following code line:

    selectedItems += "'" + table["firma"].ToString() + "', ";
  • edited 7:44PM
    Yes now ist working Tahnk you for help AlexTZ.
  • edited 7:44PM
    Can you teach me how can i pass DateTimepicker picked date to sql query i tryed changing your code but dont work.
  • edited 7:44PM
    You don't need to use any code with DateTimePicker. Write in your sql:

    select * from table where field = @param1

    Set up parameter:
    Name = param1
    DataType = DateTime
    Expression = DateTimePicker1.Value
    DefaultValue = 1/1/2000
  • edited 7:44PM
    But i have a coded report for dynamic sql query i have one paramater to Depatmant i wont to add one more to time.
  • edited 7:44PM
    Something like
    table.SelectCommand = "select * from table where field = '" + DateTimePicker1.Value.ToString("MM/dd/yyyy") + "'";
  • edited 7:44PM
    Ok its working but selected date going to query with single quote on the last of the word " 02/02/2010' " how can i convert to " '02/02/2010' "
  • edited 7:44PM
    It works well for me, all quotes are correct.
  • edited 7:44PM
    I solved quotes problem but now when i select today from datepicker going to sql '06.55.2010' like this.
  • edited 7:44PM
    and i am selecting 03.03.2010 nothing changing still same date '06.55.2010'
  • edited 7:44PM
    Sorry I can't reproduce this.
    Try to write the following code in your OK button handler:

    MessageBox.Show(DateTimePicker1.Value.ToString("MM/dd/yyyy"));

    what do you see when clicking OK button?
  • edited 7:44PM
    I see valid date 03.06.2010
  • edited 7:44PM
    In this case, the error is somewhere in your code, when you form a dynamic sql text.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.