Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

LINQ FAQ for Newbies

, 17 Jul 2009
A LINQ FAQ for newbies.
WindowsFormsLINQQuery.zip
WindowsFormsLINQQuery
WindowsFormsLINQQuery
bin
Debug
Release
WindowsFormsLINQQuery.exe
WindowsFormsLINQQuery.vshost.exe
WindowsFormsLINQQuery.vshost.exe.manifest
obj
Debug
Refactor
TempPE
Release
Refactor
TempPE
Properties
Settings.settings
WindowsFormsLINQQuery.csproj.user
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsLINQQuery
{
    public partial class frmLINQQuery : Form
    {
        public frmLINQQuery()
        {
            InitializeComponent();
        }

        private void btnFireQuery_Click(object sender, EventArgs e)
        {
           
        }

        private void cmbFireQuery_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbFireQuery.SelectedIndex == 0)
            {
                SimpleQuery();
            }
            else if (cmbFireQuery.SelectedIndex == 1)
            {
                FireQueryWithWhere(txtCustomerCode.Text);
            }
            else if (cmbFireQuery.SelectedIndex == 2)
            {
                FireWithJoin();
            }
            else if (cmbFireQuery.SelectedIndex == 3)
            {
                FireWithGroupBy();
            }
            else if (cmbFireQuery.SelectedIndex == 4)
            {
                FireWithOrderBy();
            }
        }
        private void SimpleQuery()
        {
            clsLINQ objLinq = new clsLINQ();
            lstResults.Items.Clear();
            LoadCustomersinList(objLinq.FireSimpleQuery());
        }
        private void FireQueryWithWhere(string strCustomerCode)
        {
            clsLINQ objLinq = new clsLINQ();
            lstResults.Items.Clear();
            LoadCustomersinList(objLinq.FireQueryWithWhere(strCustomerCode));
        }
        private void FireWithJoin()
        {
            clsLINQ objLinq = new clsLINQ();
            lstResults.Items.Clear();
            LoadCustomersinList(objLinq.FireQueryWithJoin());
        }
        private void FireWithGroupBy()
        {
            clsLINQ objLinq = new clsLINQ();
            lstResults.Items.Clear();
            objLinq.FireQueryWithGroupBy(lstResults);
        }
        private void FireWithOrderBy()
        {
            clsLINQ objLinq = new clsLINQ();
            lstResults.Items.Clear();
            LoadCustomersinList(objLinq.FireQueryWithOrderBy());
        }
        private void LoadCustomersinList(IEnumerable<clsCustomer> objCollection)
        {
            foreach (clsCustomer obj in objCollection)
            {
                lstResults.Items.Add(" Name :-"  + obj.CustomerName + " Code  :-" + obj.customerCode + " City  :-" + obj.City);
                foreach (clsOrder objOrder in obj.Orders)
                {
                    lstResults.Items.Add("-->" + objOrder.ProductName);
                }
            }
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shivprasad koirala
Architect http://www.questpond.com
India India

I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small
E-learning company in India. We are very much active in making training videos ,
writing books and corporate trainings. Do visit my site for 
.NET, C# , design pattern , WCF , Silverlight
, LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server  training 
and Interview questions and answers


You may also be interested in...

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 18 Jul 2009
Article Copyright 2009 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid