c# - Dynamic Linq To Sql With ComboBox and Column.Contains -


I have a text box, combo box, button and datagrid view, which is meant for searching and searching a customer. MSSQL visualization (vCustomer) is used, it works great, but I know that my code can be more efficient to represent four items in the cambod to represent the column.

Is there an easy way to convert the following from dynamic LINQ to SQL? I'm new to C # I have checked some other posts, but I do not seem to be doing this work.

  Public Partial Segment MainForm: Form {Public MainForm () {InitializeComponent (); } Private Zero MainForm_Load (Object Sender, EventArgs E) {// column filter to filter for string [] list = new string [4]; List [0] = "name"; List [1] = "not a customer's right"; List [2] = "Telephone"; List [3] = "postal"; // bind to combobox cboColumn. DataSource = list; CboColumn.SelectedIndex = 0; } Private Zero btnSearch_Click (Object Sender, EventArgs e) {try {cursor.Current = Cursors.WaitCursor; CustomerSearchDataContext DB = New CustomerSearchDatex (); IEnumerable & LT; VCustomer & gt; CustomerQuery = Faucet; Switch (cboColumn.SelectedIndex) {Case 0: db.vCustomers in C by customerQuery = where c.Name.Contains (txtSearch.Text) order c.CustomerAccountNo descending selection c; break; Case 1: Customer's comparison = Customer from db.v, where c.Name.Contains (txtSearch.Text) orders c.CustomerAccountNo descending selection c; break; Case 2: Compare the customer to = db.v in the customer's c. Celephone.Contains (txtSearch.Text) by order c.CustomerAccountNo descending selection c; break; Case 3: db.v customers in customer.c = c where c.Postal.Contains (txtSearch.Text) orders by c.CustomerAccountNo descending selection c; break; } CustomerBindingSource.DataSource = customerQuery; DataGridView1.DataSource = customerBindingSource; DataGridView1.Column ["CustomerId"]. Visible = false; } Hold (System.Data.SqlClient.SqlException East) {MessageBox.Show ("An error occurred -" pre. Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Finally {cursor.Current = Cursors.Default; }}}}  

Use [System.Linq.Dynamic] [1] .

Obtain condition from one method and use it in the same query.

  switch (option) {case case1: condition = string.format ("{0}. Consultations ({1})", "column", "value" break;  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -