473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

using GetChanges on a datatable

Sam
Hi,
I have a datagrid which source is a dataset :

dgFields.Rows.DataMember = m_dsFields.Tables(0).TableName
dgFields.Rows.DataSource = m_dsFields

Now my values are displayed properly and when I add a row I call the
follwing :

Dim dtChanged As New DataTable
dtChanged = m_dsFields.Tables(0).GetChanges(DataRowState.Added )

but dtChanged is always equal to Nothing.

What am I doing wrong ?

thx

Nov 21 '05 #1
24 5404
Sam,

Can you show how you show us how you add the datarow, yesterday there was
somebody who thought he added it, however that was not done, there was alone
a new datarow created.

Cor
Nov 21 '05 #2
Sam
humm...
To be honnest I don't add anything. At the bottom of my datagrid there
is a new line so I fill in the txtboxes and that's it. I would assume
then that the changes made to the datagrid are reflected on to the
datasource, but I might be wrong.

The code above is all I do. What is missing ?

Nov 21 '05 #3
Sam
Actually it might be important that I mention that I've tried the exact
same code with the parameters DataRowState.Modified and
DatarowState.Deleted, and that in both cases, my dtChanged is filled
with the right lines !!!!
Therefore I believe my code is correct, however something is wrong with
DatarowState.Added or I'm missing something here !

Nov 21 '05 #4
Sam,

You add probably a row using the datagrid.

Set this before your get changes than probably it will go.

\\\
BindingContext(m_dsFields.Tables(0)).EndCurrentEdi t
///
This pushes the changes from the datagrid into the dataset when there has
not been a rowchange.
I hope this helps,

Cor
Nov 21 '05 #5
Sam
Cor,
I've done that:
Dim dtChanged As New DataTable
BindingContext(m_dsFields.Tables(0)).EndCurrentEdi t()
dtChanged = m_dsFields.Tables(0).GetChanges(DataRowState.Added )

But dtChanged is still Nothing :( I really don't understand why. That's
a pain !
What does BindingContext here ?

Nov 21 '05 #6
Sam
Cor,
Actually I've noticed that it works with DataRowState.Modified. I mean
that even newly added rows are contained in dtChanged. I guess I can
use that if I can't get the Added method to work

Nov 21 '05 #7
Sam,

Try this sample partially with your code, I had not any problem, it works
in my opinion as you and I would expect.
\\\needs a datagrid and a button on a form
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("Place")
dt.Columns.Add("Name")
dt.Columns.Add("Key")
dt.LoadDataRow(New Object() {"Whatever", "Sam", "1"}, True)
dt.LoadDataRow(New Object() {"Whatelse", "Cor", "2"}, True)
DataGrid1.DataSource = dt
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dtChanged As New DataTable
BindingContext(dt).EndCurrentEdit()
dtChanged = dt.GetChanges(DataRowState.Added)
DataGrid1.DataSource = Nothing
DataGrid1.DataSource = dtChanged
End Sub
///
I hope this helps,

Cor
Nov 21 '05 #8
Sam
Thx Cor,
unfortunately it doesn't work for me. My dtChanged is still Nothing....
I'm giving up, I will use DataRowState.Modified instead...

Nov 21 '05 #9
Sam,
unfortunately it doesn't work for me. My dtChanged is still Nothing....
I'm giving up, I will use DataRowState.Modified instead...

Did you try my sample, because it shows that dtChanged in the datagrid.

Cor
Nov 21 '05 #10
Sam
well I've tried your code in my program :

Dim dtChanged As New DataTable
BindingContext(m_dsFields.Tables(0)).EndCurrentEdi t()

dtChanged = m_dsFields.Tables(0).GetChanges(DataRowState.Added )
dgFields.Rows.DataSource = Nothing
dgFields.Rows.DataSource = dtChanged

and unfortunately dtChanged still is Nothing !

Nov 21 '05 #11
Sam,

However as in my first question, how you are so sure you added a row?

Cor
Nov 21 '05 #12
Sam
I'd like to know what you mean by 'adding a row'.
I add stuff in my cells of the last row of my datagrid (the one marked
by a *)
From the moment I add things in this row, I would assume that the

datasource of this grid should be modified (in fact
DataRowState.Modified works) but apparentely it doesn't detect an added
row

Sam.

Nov 21 '05 #13
Sam,

Why not try my sample complete?

Cor
Nov 21 '05 #14
Sam
Because I trust you, I know your code is working, but the thing is that
my code is the same as yours !

Nov 21 '05 #15
Sam,

There is a new Pope, that is not a miracle, so what is the miracle here.

What Net version are you using.

Cor
Nov 21 '05 #16
Are you sure that you click the star

enter data
click the pencil

Cor
Nov 21 '05 #17
Sam
er.. no I didn't know I had to click the pencil ..... I'll try
thx

Nov 21 '05 #18
Sam
Cor,
I've tried that but dtChanged is still nothing.
my code :

Dim dtChanged As New DataTable
BindingContext(m_dsFields.Tables(0)).EndCurrentEdi t()
dtChanged = m_dsFields.Tables(0).GetChanges(DataRowState.Added )
dgFields.Rows.DataSource = Nothing
dgFields.Rows.DataSource = dtChanged

The thing to note here is that m_dsFields contains the new row ! But
dtChanged does not. So this is weird. Maybe I should have mentionned
that I'm not using the microsoft datagrid but a third party control
(FlyGrid). However this control should not have any influence on
DataRowState.Added and as I said, m_dsFields is properly modified
anyway.

Nov 21 '05 #19
Sam,

Why not try it with a normal grid and otherwise.
dtChanged = m_dsFields.Tables(0).GetChanges(DataRowState.Added ) messagebox.show(dtChanged.Rows.Count.ToString)
dgFields.Rows.DataSource = Nothing
dgFields.Rows.DataSource = dtChanged
Cor

"Sam" <sa**************@voila.fr> schreef in bericht
news:11*********************@f14g2000cwb.googlegro ups.com... Cor,
I've tried that but dtChanged is still nothing.
my code :

Dim dtChanged As New DataTable
BindingContext(m_dsFields.Tables(0)).EndCurrentEdi t()
dtChanged = m_dsFields.Tables(0).GetChanges(DataRowState.Added )
dgFields.Rows.DataSource = Nothing
dgFields.Rows.DataSource = dtChanged

The thing to note here is that m_dsFields contains the new row ! But
dtChanged does not. So this is weird. Maybe I should have mentionned
that I'm not using the microsoft datagrid but a third party control
(FlyGrid). However this control should not have any influence on
DataRowState.Added and as I said, m_dsFields is properly modified
anyway.

Nov 21 '05 #20
Sam
I have to use this grid.
I cant display the number of rows since dtChanged is nothing.

Nov 21 '05 #21
Sam,

You make me crazy (not really) , can you try this one?

m_dsFields.Tables(0).Rows.Add(m_dsFields.Tables(0) .NewRow)
Dim dtChanged As New DataTable
dtChanged = m_dsFields.Tables(0).GetChanges(DataRowState.Added )
messagebox.show(dtChanged.Rows.Count.ToString)

Cor
Nov 21 '05 #22
Sam
sorry ;)
I'll try

Nov 21 '05 #23
Sam
yes that works !
Would that mean it comes from the grid ? I'll have to look into this...
thx

Nov 21 '05 #24
Sam
Cor,
For your information, the Flygrid control HAS a bug, which is DataAdded
can't be used at the moment with GetChanges. It will be fixed in the
next release according to the guys who developped it. So much time
spent on this crap for nothing.... sorry.

Nov 21 '05 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul | last post by:
I am writing a DataBase Client/Server pair of applications in C#. The client registers a query, the server populates a dataset and its contents sent via XML to be displayed in the client DataGrid....
1
by: Marty | last post by:
In winforms, I can bind a datagrid to a dataset. When the user wants to submit changes, it's easy to see what has changed with the DataSet "GetChanges" method. In ASP.Net, I can create the...
4
by: Sam | last post by:
Hi, Some people are going to say I drive them crazy again...but here we go... I have the following code : BindingContext(m_dsFields.Tables(0)).EndCurrentEdit() Dim dtModifiedData As...
4
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and...
1
by: matt | last post by:
hello, i have a web app that allows users to query our oracle db and produce a dataset of report data. they then have the option to serialize this data and store it in the database. later, then...
1
by: daranee | last post by:
Documentation on GetChanges say the following: Gets a copy of the DataSet that contains all changes made to it since it was loaded or AcceptChanges was last called. Does this mean I can update via...
4
by: Matteo Migliore | last post by:
Hi. I writed a method that takes two DataTable with same schema and return a third DataTable that: - insert new rows from "compare" DataTable - delete rows contained in "source" and not in...
0
LoanB
by: LoanB | last post by:
Hey guys need some info here. I am adding, updating and deleting data on a datagrid. I pass the datagrid's datasource (datatable dt) to my data layer. Assuming I have already created and...
3
by: John Sheppard | last post by:
Hello there, I have the following code; I do this as a work around for a dataset.haschanges method which doesnt appear to work correctly either For Each dt As DataTable In myDs.Tables If Not...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.