Динамический Linq к Sql с ComboBox и столбцом. Содержит

попробуйте xctool, это замена для xcodebuild от Apple, которая упрощает создание и тестирование продуктов для iOS и Mac. Это особенно полезно для непрерывной интеграции. Он имеет несколько дополнительных функций:

  1. Запускает те же тесты, что и Xcode.app.
  2. Структурированный вывод результатов сборки и тестирования.
  3. Удобный для человека цвет ANSI.

№ 3 чрезвычайно полезен. Я не могу, если кто-то может прочитать вывод консоли xcodebuild, я не могу, обычно он дает мне одну строку с 5000+ символами. Даже труднее читать, чем дипломную работу.

xctool: https://github.com/facebook/xctool

1
задан robnardo 25 June 2009 в 17:19
поделиться

2 ответа

Используйте [System.Linq.Dynamic] [1] .

Получите условие из метода и используйте его в одном запросе.

    switch (choice)
    {
        case case1:
            condition = string.Format("{0}.Contains({1})", "Column", "Value"
            break;
2
ответ дан 3 September 2019 в 01:13
поделиться

Hey Rony. I tried your suggestion and re factored my code (see below). However, I receive an error: No property or field 'smith' exists in type 'vCustomer' . By the way, the MessageBox.Show(condition); line returns Name.Contains(smith) which looks correct.

What am I doing wrong? Sorry for being a noob and thanks for your help.

Figured it out... needed to wrap search string with double quotes! Code has been edited.

public partial class MainForm : Form
{
    public MainForm()
    {
        InitializeComponent();
    }
    private void MainForm_Load(object sender, EventArgs e)
    {
        // data column to filter against
        string[] list = new string[4];
        list[0] = "Name";
        list[1] = "CustomerAccountNo";
        list[2] = "Telephone";
        list[3] = "Postal";
        cboColumn.DataSource = list;
        cboColumn.SelectedIndex = 0;

        // left, right or middle search
        string[] list2 = new string[3];
        list2[0] = "Contains";
        list2[1] = "StartsWith";
        list2[2] = "EndsWith";
        cboFilterAtt.DataSource = list2;
        cboFilterAtt.SelectedIndex = 0;
    }

    private void btnSearch_Click(object sender, EventArgs e)
    {
        try
        {
            Cursor.Current = Cursors.WaitCursor; 
            CustomerSearchDataContext db = new CustomerSearchDataContext();
            //string condition = string.Format("{0}.{1}({2})", cboColumn.SelectedValue, cboFilterAtt.SelectedValue, txtSearch.Text);
            string condition = string.Format("{0}.{1}({2})", cboColumn.SelectedValue, cboFilterAtt.SelectedValue, "\"" + txtSearch.Text + "\"");
            MessageBox.Show(condition);
            var customerQuery = db.vCustomers.Where(condition).OrderBy("CustomerAccountNo");
            customerBindingSource.DataSource = customerQuery;
            dataGridView1.DataSource = customerBindingSource;
            dataGridView1.Columns["CustomerId"].Visible = false;
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            MessageBox.Show("An Error Occured - " + ex.Message,"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        finally
        {
            Cursor.Current = Cursors.Default; 
        }
    }
}
0
ответ дан 3 September 2019 в 01:13
поделиться
Другие вопросы по тегам:

Похожие вопросы: