예제 #1
0
        private void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            //odswiezanie datagrid

            LINQtoSQLclassExample1DataContext databaseConnection_tmp = new LINQtoSQLclassExample1DataContext();

            datagrid3.ItemsSource = null;

            datagrid3.UpdateLayout();
            datagrid3.Items.Refresh();
            datagrid3.ItemsSource = databaseConnection_tmp.Customers;
        }
예제 #2
0
        private void LoadButton2_Click(object sender, RoutedEventArgs e)
        {
            //Wyszukuje najwieksza liczbe z kolumny CustomerID konwertujac wczesniej do INT32, bo na samym stringu nie zadziala

            var maxCustomerIdFromDB = (from max_db in databaseConnection.Customers
                                       where max_db.CustomerID != null
                                       select Convert.ToInt32(max_db.CustomerID)).Max();

            int max = maxCustomerIdFromDB + 1;

            string nextCustomerID = max.ToString();


            //Nowy obiekt ktory przechowuje to co bedziemy chcieli zapisac w DB
            Customer customerInsert = new Customer
            {
                CustomerID  = nextCustomerID,
                CompanyName = textBox.Text,
                ContactName = textBox2.Text,
                Phone       = textBox3.Text
            };

            //szykujemy rozkaz do wyslania
            databaseConnection.Customers.InsertOnSubmit(customerInsert);


            //wysylamy rozkaz z obsluga bledow
            try
            {
                databaseConnection.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
            }
            catch (Exception exeption_db1)
            {
                Console.WriteLine(exeption_db1);

                databaseConnection.SubmitChanges();
            }

            //odswiezanie datagrid

            LINQtoSQLclassExample1DataContext databaseConnection_tmp = new LINQtoSQLclassExample1DataContext();

            datagrid3.ItemsSource = null;

            datagrid3.UpdateLayout();
            datagrid3.Items.Refresh();
            datagrid3.ItemsSource = databaseConnection_tmp.Customers;
        }