Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
QuestionToll management Pin
Member 1278484315-Mar-17 21:26
Member 1278484315-Mar-17 21:26 
AnswerRe: Toll management Pin
OriginalGriff15-Mar-17 21:32
mveOriginalGriff15-Mar-17 21:32 
QuestionRe: Toll management Pin
ZurdoDev16-Mar-17 5:40
professionalZurdoDev16-Mar-17 5:40 
JokeRe: Toll management Pin
Richard MacCutchan16-Mar-17 6:35
mveRichard MacCutchan16-Mar-17 6:35 
GeneralRe: Toll management Pin
ZurdoDev16-Mar-17 7:04
professionalZurdoDev16-Mar-17 7:04 
GeneralRe: Toll management Pin
Richard MacCutchan16-Mar-17 7:13
mveRichard MacCutchan16-Mar-17 7:13 
AnswerRe: Toll management Pin
Patrice T17-Mar-17 14:35
mvePatrice T17-Mar-17 14:35 
QuestionMulti-threading Efficiency Pin
MAW3015-Mar-17 16:11
MAW3015-Mar-17 16:11 
AnswerRe: Multi-threading Efficiency Pin
Mycroft Holmes15-Mar-17 16:38
professionalMycroft Holmes15-Mar-17 16:38 
GeneralRe: Multi-threading Efficiency Pin
MAW3015-Mar-17 17:39
MAW3015-Mar-17 17:39 
GeneralRe: Multi-threading Efficiency Pin
Eddy Vluggen16-Mar-17 1:17
professionalEddy Vluggen16-Mar-17 1:17 
AnswerRe: Multi-threading Efficiency Pin
Pete O'Hanlon15-Mar-17 22:49
mvePete O'Hanlon15-Mar-17 22:49 
QuestionC# Class Documentation on MSDN Pin
Winnie D14-Mar-17 9:32
Winnie D14-Mar-17 9:32 
AnswerRe: C# Class Documentation on MSDN Pin
Eddy Vluggen14-Mar-17 9:47
professionalEddy Vluggen14-Mar-17 9:47 
GeneralRe: C# Class Documentation on MSDN Pin
Winnie D14-Mar-17 10:40
Winnie D14-Mar-17 10:40 
GeneralRe: C# Class Documentation on MSDN Pin
CHill6014-Mar-17 12:54
mveCHill6014-Mar-17 12:54 
GeneralRe: C# Class Documentation on MSDN Pin
Mycroft Holmes14-Mar-17 14:28
professionalMycroft Holmes14-Mar-17 14:28 
GeneralRe: C# Class Documentation on MSDN Pin
Kevin McFarlane15-Mar-17 2:15
Kevin McFarlane15-Mar-17 2:15 
AnswerRe: C# Class Documentation on MSDN Pin
Afzaal Ahmad Zeeshan14-Mar-17 10:03
professionalAfzaal Ahmad Zeeshan14-Mar-17 10:03 
GeneralRe: C# Class Documentation on MSDN Pin
Winnie D14-Mar-17 11:37
Winnie D14-Mar-17 11:37 
SuggestionRe: C# Class Documentation on MSDN Pin
Richard Deeming14-Mar-17 11:15
mveRichard Deeming14-Mar-17 11:15 
QuestionDataGridView NOT adding with Entities models Pin
nabilg14-Mar-17 4:14
nabilg14-Mar-17 4:14 
Hello,
I'm using a datagridview in windowsform application and would like to make changes and adding new records into my Datagridview.
After calling the BD.SavChanges() and using the BD.ChangeTracker.Entries(), only the modified rows are updated into the SQL table and no added rows.
Can you help me for this?
The DataGridView1.DataSource is the gammeBindingSource on the Form.

This is the code form my Form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Entity.Infrastructure;

namespace PRODATA
{
    public partial class Gammes : Form
    {
        PRODATAEntities BD;
        public Gammes()
        {
            InitializeComponent();
        }

        private void Gammes_Load(object sender, EventArgs e)
        {
            BD = new PRODATAEntities();
            BD.Configuration.ProxyCreationEnabled = false;
            BD.Configuration.LazyLoadingEnabled = false;

            gammeBindingSource.DataSource = BD.Gammes.ToList();

        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            try
            {
                foreach (DbEntityEntry entry in BD.ChangeTracker.Entries())
                {
                    switch (entry.State)
                    {
                        case EntityState.Added:
                            entry.CurrentValues["Utilisateur"] = ((PRODATAparent)(this.MdiParent)).mUtilisateur;
                            entry.CurrentValues["Dateheure"] = DateTime.Now;
                            break;
                        case EntityState.Modified:
                            entry.CurrentValues["Utilisateur"] = ((PRODATAparent)(this.MdiParent)).mUtilisateur;
                            entry.CurrentValues["Dateheure"] = DateTime.Now;
                            break;
                        case EntityState.Deleted:
                            break;
                    }
                }
                dataGridView1.EndEdit();
                gammeBindingSource.EndEdit();
                BD.SaveChanges();
                MessageBox.Show("Enregistrement effectué...", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                gammeBindingSource.ResetBindings(false);
            }
        }
    }
}

Best regards.


modified 14-Mar-17 10:27am.

QuestionManage a timeout on a ldap connection Pin
MarcSchmidtmayer13-Mar-17 1:04
MarcSchmidtmayer13-Mar-17 1:04 
AnswerRe: Manage a timeout on a ldap connection Pin
Garth J Lancaster13-Mar-17 1:34
professionalGarth J Lancaster13-Mar-17 1:34 
GeneralRe: Manage a timeout on a ldap connection Pin
MarcSchmidtmayer13-Mar-17 2:27
MarcSchmidtmayer13-Mar-17 2:27 

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.