The 'Merge()' method actually works on Primary Key. It seems that either
your Tables do NOT contain the Primary Key or 'dt_aux' gets new Primary
Key(s) each time. OK there is another workaround for this,

1) first clear the 'dt' [dt.Clear()]
2) then call the merge() method [dt.Merge(dt_aux)]

OR you can add a Primary Key in the tables if this is possible. In this way
you don't have to clear the 'dt'.

Notice that my main objective is: "don't create new instances and don't
change the DataGridView's DataSource property"

Regards,
Arsalan Tamiz

On Mon, Feb 23, 2009 at 4:54 AM, Nacho108 <[email protected]> wrote:

>
> Thanks Arsalan for this advice. I've tried this and the merge method
> add the dt_aux's rows to the dt's rows, so after the merge I have
> twice the quantity of rows I had before in it.
> By the way, I'm using the backgroundworker to read the database.
>
> Any other ideas?
>
>
> On Feb 22, 1:28 pm, sallushan <[email protected]> wrote:
> > @Vinicius
> >
> > OP is talking about Windows Forms (Desktop Application) NOT Web
> > Application.
> >
> > On Feb 21, 10:53 pm, Vinicius Quaiato <[email protected]>
> > wrote:
> >
> > > Are you using .NET AJAX?
> >
> > > On Sat, Feb 21, 2009 at 12:06 PM, Nacho108 <[email protected]>
> wrote:
> >
> > > > Thanks Alarsan for the explanation, but I'm taking a little bit
> > > > different approach here. As for my little experience, ANYTHING
> > > > connected with windows controls shouldn't be modified from another
> > > > thread than the main. It throws exceptions that are very difficult to
> > > > debug.
> > > > That's why I read the data from the database, I put it in an
> auxiliary
> > > > datatable and then I COPY this to the real DT. Also, I don't make a
> > > > NEW datatable each time I read the database. I'm doing this:
> >
> > > > 1) Read the data from SQL and put it in a auxiliary datatable
> > > > (dt_aux).
> > > > 2) I process dt_aux and afterwards place it into dt with this line:
> > > >  dt=filtra_activas(dt_aux.Copy());                (filtra_activa is a
> > > > procedure which make some process with the dt_aux's rows)
> > > > 3) dataGridView1.datasource=dt; (Assign the dt to the dataGridView
> > > > every time, since otherwise it
> > > > doesn't notice if the dt have changed)
> >
> > > > Is there something else I'm doing wrong?
> >
> > > > On Feb 20, 5:37 pm, Vinicius Quaiato <[email protected]>
> > > > wrote:
> > > > > Well... The UI need to be refreshed... i'm not seeing how to do it.
> >
> > > > > You may to do something in ajax to update just the rows in the grid
> that
> > > > > have the data content changed... is it possible for you?
> >
> > > > > 2009/2/20 Nacho108 <[email protected]>
> >
> > > > > > Hi, thanks for answering.
> > > > > > I have to process the data from the database and place it in a
> > > > > > datatable in order to do it.
> > > > > > In brief I'm doing something like this:
> >
> > > > > > 1) Read the data from SQL and put it in a datatabel (dt_aux).
> > > > > > 2) Process dt_aux and place it into dt with this line
> > > > > >  dt=filtra_activas(dt_aux.Copy());
> > > > > > 3) Assign the dt to the datagridview every time, since otherwise
> it
> > > > > > doesn't notice wether the dt have changed.
> >
> > > > > > So I cannot bind directly the datagridview with the SQL.
> >
> > > > > > Any other idea? (or maybe go further on the explanation on this
> one if
> > > > > > I've got it wrong)
> >
> > > > > > On Feb 20, 4:31 pm, Vinicius Quaiato <[email protected]
> >
> > > > > > wrote:
> > > > > > > Hi,
> >
> > > > > > > Try to bind a SqlDataSource in the Grid, then just call the
> > > > DataBind()
> > > > > > > method instead of set the DataSource;
> >
> > > > > > > 2009/2/20 Nacho108 <[email protected]>
> >
> > > > > > > > Hi Everyone !
> >
> > > > > > > > I'm having a problem with a Datagridview control, I hope
> somebody
> > > > can
> > > > > > > > help me since I tried many things but I cannot nail the
> solution.
> > > > > > > > I have a Datagridview displaying the contents of a database
> that
> > > > > > > > change continuously, but the changes are minimum (around 2 or
> 3
> > > > rows
> > > > > > > > change over 180, every 10 seconds), and I'm reading this
> database
> > > > > > > > through a separated thread and then refreshing the
> datagridview
> > > > each
> > > > > > > > 10 seconds. All the threading thing is already debugged and
> working
> > > > > > > > fine. The problem is not connected with it.
> > > > > > > > The user should be able to scroll the datagridview normally
> during
> > > > the
> > > > > > > > refresh process, but it happens that when the program comes
> to this
> > > > > > > > line where I update the datagridview itself (after reading
> the
> > > > > > > > database):
> >
> > > > > > > > dataGridView1.DataSource = dt;     (dt is a datatable which I
> > > > populate
> > > > > > > > with database values)
> >
> > > > > > > > If I were scrolling with the mouse, the mouse looses control
> and I
> > > > > > > > have to take again the scroll bar, this is very anoying for
> the
> > > > user
> > > > > > > > since refresh is very often.
> >
> > > > > > > > I don't know if I'm doing things right, so I have a few
> questions:
> >
> > > > > > > > 1) If I don't assign the datasource in each database reading,
> the
> > > > > > > > control doesn't refresh its content. Is this normal? The
> > > > datagridview
> > > > > > > > content shouldn't automatically follow the content of dt
> > > > (datatable)?
> >
> > > > > > > > 2) In case this assign I describe before is necessary, is
> there a
> > > > way
> > > > > > > > to avoiding this loose of control I'm experimenting?
> >
> > > > > > > > Thanks in advance
> > > > > > > > Nacho
>

Reply via email to