tags:

views:

59

answers:

1
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 Advanced_LinQ_Query
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private DataClasses1DataContext database = new DataClasses1DataContext();

        private void Form1_Load(object sender, EventArgs e)

        {
            database.Log= Console.Out;
            comboBox.SelectedIndex=0;
        }

        private void titleBindingNavigatorSaveItem_Click(object sender, EventArgs e)

        {
               Validate();
               titleBindingSource.EndEdit();
               database.SubmitChanges();
               comboBox.SelectedIndex=0;
        }

        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox.SelectedIndex)
            {
                case 0:
                    titleBindingSource.DataSource =
                        from Title in database.Titles
                        orderby Title.BookTitle
                        select Title;
                    break;

                case 1:
                    titleBindingSource.DataSource =
                        from Title in database.Titles
                        where Title.Copyright == "2008"
                        orderby Title.BookTitle
                        select Title;
                    break;

                case 2:
                    titleBindingSource.DataSource =
                        from Title in database.Titles
                        where Title.BookTitle.EndsWith("How to Program")
                        orderby Title.BookTitle
                        select Title;
                    break;
            }
            titleBindingSource.MoveFirst();

        }
    }        
}

no connection seems to built after debugging between Title table in my database (book.mdf) and titleBindingSource! Where is the problem?

A: 

You should call titleBindingSource.Bind(); I believe.

Nissan Fan
That is required for webforms, but this is Winforms.
ck