Click here to Skip to main content
15,908,020 members
Home / Discussions / C#
   

C#

 
AnswerRe: Issue using WHERE clause in LINQ query Pin
Richard Deeming9-Jun-14 5:58
mveRichard Deeming9-Jun-14 5:58 
GeneralRe: Issue using WHERE clause in LINQ query Pin
Member 102279589-Jun-14 7:04
Member 102279589-Jun-14 7:04 
QuestionI have 2 question Pin
roza548-Jun-14 2:06
roza548-Jun-14 2:06 
QuestionRe: I have 2 question Pin
Richard MacCutchan8-Jun-14 2:20
mveRichard MacCutchan8-Jun-14 2:20 
AnswerRe: I have 2 question Pin
OriginalGriff8-Jun-14 2:21
mveOriginalGriff8-Jun-14 2:21 
QuestionDBConcurrencyException problem Pin
Member 108711908-Jun-14 0:12
Member 108711908-Jun-14 0:12 
AnswerRe: DBConcurrencyException problem Pin
Dave Kreskowiak8-Jun-14 3:06
mveDave Kreskowiak8-Jun-14 3:06 
GeneralRe: DBConcurrencyException problem Pin
Member 108711908-Jun-14 5:11
Member 108711908-Jun-14 5:11 
Here is my C# code which updates the database.

C#
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UpdateDatabase();
        }
private void UpdateDatabase()
        {
            if (this.Validate())
            {
                this.receptTableBindingSource.EndEdit();

                try
                {
                    this.receptTableTableAdapter.Update(this.receptDataSet.ReceptTable);
                    MessageBox.Show("Update successful");
                }
                catch (DBConcurrencyException dbcx)
                {
                    DialogResult response = MessageBox.Show(CreateMessage((ReceptDataSet.ReceptTableRow)
                        (dbcx.Row)), "Concurrency Exception", MessageBoxButtons.YesNoCancel);

                    ProcessDialogResult(response);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error was thrown while attempting to update the database: " + ex.ToString());
                }
            }
        }

        private string CreateMessage(ReceptDataSet.ReceptTableRow cr)
        {
            return
                "Database(Cancel): " + GetRowData(GetCurrentRowInDB(cr), DataRowVersion.Default) + "\n" +
                "Original(No): " + GetRowData(cr, DataRowVersion.Original) + "\n" +
                "Proposed(Yes): " + GetRowData(cr, DataRowVersion.Current) + "\n" +
                "Do you still want to update the database with the proposed value?";
        }


        //-------------------------------------------------------------------------- 
        // This method loads a temporary table with current records from the database 
        // and returns the current values from the row that caused the exception. 
        //-------------------------------------------------------------------------- 
        private ReceptDataSet.ReceptTableDataTable tempReceptDataTable =
            new ReceptDataSet.ReceptTableDataTable();

        private ReceptDataSet.ReceptTableRow GetCurrentRowInDB(ReceptDataSet.ReceptTableRow RowWithError)
        {
            this.receptTableTableAdapter.Fill(tempReceptDataTable);

            ReceptDataSet.ReceptTableRow currentRowInDb =
                  tempReceptDataTable.FindByID(RowWithError.ID);// tempCustomersDataTable.FindByCustomerID(RowWithError.CustomerID);

            return currentRowInDb;
        }


        //-------------------------------------------------------------------------- 
        // This method takes a CustomersRow and RowVersion  
        // and returns a string of column values to display to the user. 
        //-------------------------------------------------------------------------- 
        private string GetRowData(ReceptDataSet.ReceptTableRow custRow, DataRowVersion RowVersion)
        {
            string rowData = "";

            for (int i = 0; i < custRow.ItemArray.Length; i++)
            {
                rowData = rowData + custRow[i, RowVersion].ToString() + " ";
            }
            return rowData;
        }

        private void ProcessDialogResult(DialogResult response)
        {
            switch (response)
            {
                case DialogResult.Yes: //új mentése
                    receptDataSet.Merge(tempReceptDataTable, true, MissingSchemaAction.Ignore);
                    UpdateDatabase();
                    break;

                case DialogResult.Cancel: //jelenlegi megtartása
                    receptDataSet.Merge(tempReceptDataTable);
                    MessageBox.Show("Update cancelled");
                    break;

                case DialogResult.No: //eredeti visszaállítása
                    receptDataSet.RejectChanges();
                    receptDataSet.Merge(tempReceptDataTable, true, MissingSchemaAction.Ignore);
                    UpdateDatabase();
                    break;
            }
        }

GeneralRe: DBConcurrencyException problem Pin
Member 108711908-Jun-14 5:14
Member 108711908-Jun-14 5:14 
GeneralRe: DBConcurrencyException problem Pin
Dave Kreskowiak8-Jun-14 14:36
mveDave Kreskowiak8-Jun-14 14:36 
GeneralRe: DBConcurrencyException problem Pin
Member 108711908-Jun-14 23:56
Member 108711908-Jun-14 23:56 
GeneralRe: DBConcurrencyException problem Pin
Member 108711909-Jun-14 1:05
Member 108711909-Jun-14 1:05 
QuestionShare access to a stream, logfile name, and a locker between two classes (objects) Pin
Marco Bertschi6-Jun-14 8:56
protectorMarco Bertschi6-Jun-14 8:56 
GeneralRe: Share access to a stream, logfile name, and a locker between two classes (objects) Pin
PIEBALDconsult6-Jun-14 18:22
mvePIEBALDconsult6-Jun-14 18:22 
AnswerRe: Share access to a stream, logfile name, and a locker between two classes (objects) Pin
Gary R. Wheeler7-Jun-14 2:19
Gary R. Wheeler7-Jun-14 2:19 
GeneralRe: Share access to a stream, logfile name, and a locker between two classes (objects) Pin
Marco Bertschi7-Jun-14 2:33
protectorMarco Bertschi7-Jun-14 2:33 
GeneralRe: Share access to a stream, logfile name, and a locker between two classes (objects) Pin
OriginalGriff7-Jun-14 3:59
mveOriginalGriff7-Jun-14 3:59 
GeneralRe: Share access to a stream, logfile name, and a locker between two classes (objects) Pin
Marco Bertschi7-Jun-14 4:26
protectorMarco Bertschi7-Jun-14 4:26 
GeneralRe: Share access to a stream, logfile name, and a locker between two classes (objects) Pin
OriginalGriff7-Jun-14 4:54
mveOriginalGriff7-Jun-14 4:54 
GeneralRe: Share access to a stream, logfile name, and a locker between two classes (objects) Pin
Marco Bertschi7-Jun-14 6:14
protectorMarco Bertschi7-Jun-14 6:14 
GeneralRe: Share access to a stream, logfile name, and a locker between two classes (objects) Pin
PIEBALDconsult7-Jun-14 4:37
mvePIEBALDconsult7-Jun-14 4:37 
GeneralRe: Share access to a stream, logfile name, and a locker between two classes (objects) Pin
Marco Bertschi7-Jun-14 6:11
protectorMarco Bertschi7-Jun-14 6:11 
QuestionNeed to get readable address from latitude and longitude in windows form application using c# Pin
Godwinsmith5-Jun-14 18:54
professionalGodwinsmith5-Jun-14 18:54 
AnswerRe: Need to get readable address from latitude and longitude in windows form application using c# PinPopular
Bernhard Hiller5-Jun-14 20:58
Bernhard Hiller5-Jun-14 20:58 
GeneralRe: Need to get readable address from latitude and longitude in windows form application using c# Pin
Godwinsmith5-Jun-14 23:23
professionalGodwinsmith5-Jun-14 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.