albert albert

albert albert

  • NA
  • 524
  • 0

Search function with LINQ

Sep 2 2013 3:54 PM
HI everybody,

I have  a grid, a buttono and a textfield, like this:

[code]
using System;
using System.Linq;
using System.Windows.Forms;
//using System.Data.Linq.DataContext;
using System.Data.Linq;
//using System.Net.FtpClient;




namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private string _connectionString = @"SAVANTKING99-PC";
        //DataClasses1DataContext context = new DataClasses1DataContext(_connectionString);

        public Form1()
        {
            InitializeComponent();
            DataContext hallo = new DataContext(_connectionString);

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataClasses1DataContext context = new DataClasses1DataContext(_connectionString);
            var selectTrip = from tripElement in context.EMPLOYEE_TBLs
                             where tripElement.CITY == "Den Haag"
                             select tripElement;
        }


        void getTrip()
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext context = new DataClasses1DataContext(_connectionString);
            var selectTrip = from t in context.EMPLOYEE_TBLs
                             select new
                             {
                                 TripID = t.EMP_ID,
                                 TripCode = t.FIRST_NAME

                             };
            dataGridView1.DataSource = selectTrip;

        }

        private void dataGridView1_CellContentClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
        }


        //public void IQueryable SearchTrip(string value)
        // {


        //     var portcode = from t in context.TripElements
        //                .Where(t => t.TripElementCode.Contains(value))
        //                    select new
        //                    {
        //                        TripID = t.TripElementCode

        //                    };
        //     dataGridView1.DataSource = portcode;

        //     //return portcode;


        // }

        private void Search_Click(object sender, EventArgs e)
        {
            //Search.Text = textBox1.Text;

            //DataClasses1DataContext context = new DataClasses1DataContext(_connectionString);
            //var portcode = from t in context.EMPLOYEE_TBLs
            //               where t.EMP_ID.Contains(textBox1.Text.ToString(t.TripElementCode).ToString())
            //               select new
            //               {
            //                   TripID = t.TripElementCode

            //               };
            //dataGridView1.DataSource = portcode; //textBox1.Text;// portcode;
            //   textBox1.Text = "";


        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {


        }

        private void button1_Click_1(object sender, EventArgs e)
        {

            DataClasses1DataContext context = new DataClasses1DataContext(_connectionString);
            var selectTrip = from t in context.EMPLOYEE_TBLs
                             select new
                             {
                                 TripID = t.EMP_ID,
                                 TripCode = t.FIRST_NAME

                             };
            dataGridView1.DataSource = selectTrip;

        }

        private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
[/code]
I try to make search function by this method:

private void Search_Click(object sender, EventArgs e)

That you type the First_Name in the textfield and that you press the button and the you will get the result in the grid.

THX for helping.

Answers (1)