Exemplo n.º 1
0
 private void sqlDataAdapter1_RowUpdated(object sender, System.Data.SqlClient.SqlRowUpdatedEventArgs e)
 {
     NorthwindDataSet.CustomersRow CustRow = (NorthwindDataSet.CustomersRow)e.Row; MessageBox.Show(CustRow.CustomerID.ToString()
                                                                                                   + " has been updated");
     northwindDataSet1.Customers.Clear();
     sqlDataAdapter1.Fill(northwindDataSet1.Customers);
 }
Exemplo n.º 2
0
        private NorthwindDataSet.CustomersRow GetSelectedRow()
        {
            String SelectedCustomerID = CustomersDataGridView.CurrentRow.Cells["CustomerID"].Value.ToString();

            NorthwindDataSet.CustomersRow SelectedRow = northwindDataSet1.Customers.FindByCustomerID(SelectedCustomerID);
            return(SelectedRow);
        }
Exemplo n.º 3
0
        private void AddRowButton_Click(object sender, EventArgs e)
        {
            NorthwindDataSet.CustomersRow NewRow = (NorthwindDataSet.CustomersRow)northwindDataSet1.Customers.NewRow();

            NewRow.CustomerID   = "WINGT";
            NewRow.CompanyName  = "Wingtip Toys";
            NewRow.ContactName  = "Steve Lasker";
            NewRow.ContactTitle = "CEO";
            NewRow.Address      = "1234 Main Street";
            NewRow.City         = "Buffalo";
            NewRow.Region       = "NY";
            NewRow.PostalCode   = "98052";
            NewRow.Country      = "USA";
            NewRow.Phone        = "206-555-0111";
            NewRow.Fax          = "206-555-0112";

            try
            {
                northwindDataSet1.Customers.Rows.Add(NewRow);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Add Row Failed");
            }
        }
Exemplo n.º 4
0
        //</Snippet1>


        //---------------------------------------------------------------------
        //<Snippet4>
        private string CreateMessage(NorthwindDataSet.CustomersRow cr)
        {
            return
                ("Database: " + GetRowData(GetCurrentRowInDB(cr), DataRowVersion.Default) + "\n" +
                 "Original: " + GetRowData(cr, DataRowVersion.Original) + "\n" +
                 "Proposed: " + GetRowData(cr, DataRowVersion.Current) + "\n" +
                 "Do you still want to update the database with the proposed value?");
        }
Exemplo n.º 5
0
        private NorthwindDataSet.CustomersRow GetCurrentRowInDB(NorthwindDataSet.CustomersRow RowWithError)
        {
            this.customersTableAdapter.Fill(tempCustomersDataTable);

            NorthwindDataSet.CustomersRow currentRowInDb =
                tempCustomersDataTable.FindByCustomerID(RowWithError.CustomerID);

            return(currentRowInDb);
        }
Exemplo n.º 6
0
        private void sqlDataAdapter1_RowUpdating(object sender, System.Data.SqlClient.SqlRowUpdatingEventArgs e)
        {
            NorthwindDataSet.CustomersRow CustRow = (NorthwindDataSet.CustomersRow)e.Row;
            DialogResult response = MessageBox.Show("Continue updating " + CustRow.CustomerID.ToString() + "?", "Continue Update?", MessageBoxButtons.YesNo);

            if (response == DialogResult.No)
            {
                e.Status = UpdateStatus.SkipCurrentRow;
            }
        }
Exemplo n.º 7
0
        //--------------------------------------------------------------------------
        // This method takes a CustomersRow and RowVersion
        // and returns a string of column values to display to the user.
        //--------------------------------------------------------------------------
        private string GetRowData(NorthwindDataSet.CustomersRow custRow, DataRowVersion RowVersion)
        {
            string rowData = "";

            for (int i = 0; i < custRow.ItemArray.Length; i++)
            {
                rowData = rowData + custRow[i, RowVersion].ToString() + " ";
            }
            return(rowData);
        }
Exemplo n.º 8
0
        private NorthwindDataSet.CustomersRow GetCurrentRowInDB(NorthwindDataSet.CustomersRow RowWithError)
        {
            // Load data from the Customers table to tempCustomersDataTable.
            customersTableAdapter.Fill(tempCustomersDataTable);

            // Get the row for the given customerID
            NorthwindDataSet.CustomersRow currentRowInDb =
                tempCustomersDataTable.FindByCustomerID(RowWithError.CustomerID);

            return(currentRowInDb);
        }
Exemplo n.º 9
0
        //---------------------------------------------------------------------
        void Test1Typed()
        {
            //<Snippet1>
            NorthwindDataSet.CustomersRow newCustomersRow =
                northwindDataSet1.Customers.NewCustomersRow();

            newCustomersRow.CustomerID  = "ALFKI";
            newCustomersRow.CompanyName = "Alfreds Futterkiste";

            northwindDataSet1.Customers.Rows.Add(newCustomersRow);
            //</Snippet1>


            //<Snippet3>
            //<Snippet18>
            NorthwindDataSet.CustomersRow customersRow =
                northwindDataSet1.Customers.FindByCustomerID("ALFKI");
            //</Snippet18>

            customersRow.CompanyName = "Updated Company Name";
            customersRow.City        = "Seattle";;
            //</Snippet3>


            //<Snippet5>
            northwindDataSet1.Customers[4].CompanyName = "Updated Company Name";
            northwindDataSet1.Customers[4].City        = "Seattle";
            //</Snippet5>


            //<Snippet8>
            northwindDataSet1.Customers.Rows[0].Delete();
            //</Snippet8>


            //<Snippet11>
            northwindDataSet1.Customers.AcceptChanges();
            //</Snippet11>


            //<Snippet12>
            if (northwindDataSet1.HasChanges())
            {
                // Changed rows were detected, add appropriate code.
            }
            else
            {
                // No changed rows were detected, add appropriate code.
            }
            //</Snippet12>


            //<Snippet13>
            if (northwindDataSet1.HasChanges(DataRowState.Added))
            {
                // New rows have been added to the dataset, add appropriate code.
            }
            else
            {
                // No new rows have been added to the dataset, add appropriate code.
            }
            //</Snippet13>


            //<Snippet21>
            string originalCompanyName;

            originalCompanyName = northwindDataSet1.Customers[0]
                                  ["CompanyName", DataRowVersion.Original].ToString();
            //</Snippet21>


            //<Snippet22>
            string currentCompanyName;

            currentCompanyName = northwindDataSet1.Customers[0]
                                 ["CompanyName", DataRowVersion.Current].ToString();
            //</Snippet22>
        }