locked
link to sql RRS feed

  • Question

  • namespace

    AdvWorksAdv

    {

       

    ///<summary>


       

    ///Interaction logic for MainWindow.xaml


       

    ///</summary>


       

    publicpartialclassMainWindow: Window


        {

           

    // Establish connection to database


           

    AdvDataContextDataContextdc = newAdvDataContextDataContext();

           

    List<int> TopNumbers = newList<int> { 3, 5 };

           

    publicMainWindow()

            {

                InitializeComponent();

            }

           

    privatevoidWindow_Loaded(objectsender, RoutedEventArgse)

            {

               

    // pull data from Customers table and combine with related information


               

    // from CustomerAddress and Address tables


               

    varqAddr = fromc indc.Customers

                       

    joinca indc.CustomerAddresses onc.CustomerID equalsca.CustomerID

                       

    joina indc.Addresses onca.AddressID equalsa.AddressID

                       

    selectnew{ LastName = c.LastName, Office = ca.AddressType, Addr1 = a.AddressLine1, Addr2 = a.AddressLine2 };

                dgJoins.ItemsSource = qAddr;

               

    // populate City combobox with set of Cities without repeating values


               

    varqCity = (fromc indc.Addresses

                            

    selectc.City).Distinct();

                cbxCities.ItemsSource = qCity;

                cbxCities.SelectedIndex = 0;

               

    // group sales by City of Customer and totalled for each City in asc order


               

    varqCitySales = froms indc.SalesOrderHeaders

                                

    joincu indc.Customers ons.CustomerID equalscu.CustomerID

                                

    joinca indc.CustomerAddresses oncu.CustomerID equalsca.CustomerID

                                

    joina indc.Addresses onca.AddressID equalsa.AddressID

                                

    orderbya.City

                                

    groups bya.City intogrouping

                                

    selectnew{ City = grouping.Key, Total = String.Format("{0:c2}", grouping.Sum(lt => lt.TotalDue) )};

                dgCitySalesTotals.ItemsSource = qCitySales;

               

    // populate the combo-box with Top 'N' Customers


                cbxTopNCust.ItemsSource = TopNumbers;

            }

           

    privatevoidcbxCities_SelectionChanged(objectsender, SelectionChangedEventArgse)

            {

               

    // determine the city that the user has selected


               

    stringselCity = cbxCities.SelectedItem.ToString();

               

    // pull all Customer records and their associated CustomerAddress and Address records (using a multi-table join)


               

    // only pull those who come from the selected City


               

    // format the appearance of the name details


               

    varqCityCustomers = fromcust indc.Customers

                                    

    joinca indc.CustomerAddresses oncust.CustomerID equalsca.CustomerID

                                    

    joina indc.Addresses onca.AddressID equalsa.AddressID

                                    

    wherea.City == selCity

                                    

    selectnew{ CustomerName =

                                        

    String.Format("{0} {1} {2}", cust.Title, cust.FirstName, cust.LastName), Street = a.AddressLine1 };

                dgCityCustomers.ItemsSource = qCityCustomers;

            }

           

    privatevoidcbxTopNCust_SelectionChanged(objectsender, SelectionChangedEventArgse)

            {

               

    // determine the number of Customers that should be selected


               

    inttopN = (int)((ComboBox)sender).SelectedItem;

               

    // extract those orders grouped by CustomerID and totaling the TotalDue field for those Orders


               

    // then sort in descending order of TotalDue total and select only the top 'n' records


               

    varq = (froms indc.SalesOrderHeaders

                       

    groups bys.CustomerID intogrouping

                       

    selectnew{ ID = grouping.Key, Total_Sales = grouping.Sum(lt => lt.TotalDue)})

                        .OrderByDescending(co=>co.Total_Sales)

                        .Take(topN);

                dgTopCustomersSales.ItemsSource = q;

            }

        }  

    // end class


    }  

    // end namespace

    this is what i have so you can get a basic understandiding of the tables im working with what im looking for is how i can enter a word in a text box the products will come up in the data grid

    • Moved by litdev Wednesday, April 25, 2012 7:14 PM (From:Small Basic)
    Wednesday, April 25, 2012 7:00 PM

Answers

  • Sorry about the misplacement im not used to these forums also i managed to figure it out using

    private

    voidtxtp_TextChanged(objectsender, TextChangedEventArgse)

            {

               

    varquery = frompc indc.ProductCategories

                           

    wherepc.Name.StartsWith(txtp.Text)

                           

    selectnew{ Name = pc.Name };

                dg5.ItemsSource = query;

                           

            }

    • Marked as answer by zzzdaegc Thursday, April 26, 2012 9:10 AM
    Thursday, April 26, 2012 9:10 AM

All replies

  • This forum is for the SmallBasic programming language, try a C# or other forum depending on which language you are using. 

    Also, I suggest you copy and paste your code so it can be read more easily (if the insert code block isn't working for you with spaces removed between commands and loads of unnecessary line breaks added, plain text is better).  You are less likely to get good help if your source is hard to read and even needs significant editing before anyone can use it to confirm an answer.

    e.g. the following need spaces added.

    privatevoidcbxTopNCust_SelectionChanged(objectsender, SelectionChangedEventArgse)

    Wednesday, April 25, 2012 7:14 PM
  • Ask your question in the ASP.NET Forums at the following address

    http://forums.asp.net/1227.aspx/1?ADO+NET+Entity+Framework+LINQ+to+SQL+NHibernate

    Bye.


    Luigi Bruno - Microsoft Community Contributor 2011 Award

    Wednesday, April 25, 2012 8:19 PM
  • Sorry about the misplacement im not used to these forums also i managed to figure it out using

    private

    voidtxtp_TextChanged(objectsender, TextChangedEventArgse)

            {

               

    varquery = frompc indc.ProductCategories

                           

    wherepc.Name.StartsWith(txtp.Text)

                           

    selectnew{ Name = pc.Name };

                dg5.ItemsSource = query;

                           

            }

    • Marked as answer by zzzdaegc Thursday, April 26, 2012 9:10 AM
    Thursday, April 26, 2012 9:10 AM