Edit a datatable

G

Guest

How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows.BeginEdit();
orders.Rows[8]= 800 ;
orders.Rows.EndEdit();
orders.Rows.AcceptChanges();
}
orders.AcceptChanges();
The code above doesn't do anything!
 
J

Jim Hughes

From
http://msdn2.microsoft.com/en-us/library/system.data.dataset.acceptchanges.aspx

"When you call AcceptChanges on the DataSet, any DataRow objects still in
edit-mode end their edits successfully. The RowState property of each
DataRow also changes; Added and Modified rows become Unchanged, and Deleted
rows are removed."

It does NOT say that the changes are persisted to the database! It also does
not say that the controls that are bound to the dataset will be notified
that edits have been completed.

Updating the database depends on the version of the framework you are using.
Controls may need to be rebound or have the ResetBinding method called on
the BindingSource.
 
G

Guest

I want to bind the update row to a Gridview. I am not able to see the updated
value in my gridview.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Jim Hughes said:
From
http://msdn2.microsoft.com/en-us/library/system.data.dataset.acceptchanges.aspx

"When you call AcceptChanges on the DataSet, any DataRow objects still in
edit-mode end their edits successfully. The RowState property of each
DataRow also changes; Added and Modified rows become Unchanged, and Deleted
rows are removed."

It does NOT say that the changes are persisted to the database! It also does
not say that the controls that are bound to the dataset will be notified
that edits have been completed.

Updating the database depends on the version of the framework you are using.
Controls may need to be rebound or have the ResetBinding method called on
the BindingSource.

Arne Garvander said:
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows.BeginEdit();
orders.Rows[8]= 800 ;
orders.Rows.EndEdit();
orders.Rows.AcceptChanges();
}
orders.AcceptChanges();
The code above doesn't do anything!
 
S

Sericinus hunter

Arne said:
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows.BeginEdit();
orders.Rows[8]= 800 ;
orders.Rows.EndEdit();
orders.Rows.AcceptChanges();
}
orders.AcceptChanges();
The code above doesn't do anything!


This is because of two things:

1. you did not call updateSqlData(orders), or whatever you have as
an updating counterpart to getSqlData, and

2. you don't need AcceptChanges() after modifying the rows, this will
reset row states to 'unchanded' and therefore the rows will be skipped
during update.
 
G

Guest

I don't want to update the database. I want to see my changes in a gridview.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Sericinus hunter said:
Arne said:
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows.BeginEdit();
orders.Rows[8]= 800 ;
orders.Rows.EndEdit();
orders.Rows.AcceptChanges();
}
orders.AcceptChanges();
The code above doesn't do anything!


This is because of two things:

1. you did not call updateSqlData(orders), or whatever you have as
an updating counterpart to getSqlData, and

2. you don't need AcceptChanges() after modifying the rows, this will
reset row states to 'unchanded' and therefore the rows will be skipped
during update.
 
M

Marina Levit [MVP]

This is the reason you can't post messages that just say 'this doesn't do
anything' or 'this doesn't work'.

How are we supposed to know what you are trying to do, and what you expect
to happen?

In any case, is the datatable already bound to the gridview? When are you
doing these updates? Is there a postback? What is happening here?

I am guessing that you are not rebinding to the gridview or something
similar related to timing, and thus it still shows the previous values due
to viewstate. It's really hard to say since you provided no context for
your code.

Arne Garvander said:
I don't want to update the database. I want to see my changes in a
gridview.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Sericinus hunter said:
Arne said:
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows.BeginEdit();
orders.Rows[8]= 800 ;
orders.Rows.EndEdit();
orders.Rows.AcceptChanges();
}
orders.AcceptChanges();
The code above doesn't do anything!


This is because of two things:

1. you did not call updateSqlData(orders), or whatever you have as
an updating counterpart to getSqlData, and

2. you don't need AcceptChanges() after modifying the rows, this will
reset row states to 'unchanded' and therefore the rows will be skipped
during update.
 
W

W.G. Ryan - MVP

Arne - it totally depends where this is being called from. What event is
this being handled from, Init, Page_Load, PreRender? The values may be
getting set before this is called.
Arne Garvander said:
I want to bind the update row to a Gridview. I am not able to see the
updated
value in my gridview.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Jim Hughes said:
From
http://msdn2.microsoft.com/en-us/library/system.data.dataset.acceptchanges.aspx

"When you call AcceptChanges on the DataSet, any DataRow objects still in
edit-mode end their edits successfully. The RowState property of each
DataRow also changes; Added and Modified rows become Unchanged, and
Deleted
rows are removed."

It does NOT say that the changes are persisted to the database! It also
does
not say that the controls that are bound to the dataset will be notified
that edits have been completed.

Updating the database depends on the version of the framework you are
using.
Controls may need to be rebound or have the ResetBinding method called on
the BindingSource.

message
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows.BeginEdit();
orders.Rows[8]= 800 ;
orders.Rows.EndEdit();
orders.Rows.AcceptChanges();
}
orders.AcceptChanges();
The code above doesn't do anything!
 
G

Guest

I have reformulated my problem in a separate post.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Marina Levit said:
This is the reason you can't post messages that just say 'this doesn't do
anything' or 'this doesn't work'.

How are we supposed to know what you are trying to do, and what you expect
to happen?

In any case, is the datatable already bound to the gridview? When are you
doing these updates? Is there a postback? What is happening here?

I am guessing that you are not rebinding to the gridview or something
similar related to timing, and thus it still shows the previous values due
to viewstate. It's really hard to say since you provided no context for
your code.

Arne Garvander said:
I don't want to update the database. I want to see my changes in a
gridview.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Sericinus hunter said:
Arne Garvander wrote:
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows.BeginEdit();
orders.Rows[8]= 800 ;
orders.Rows.EndEdit();
orders.Rows.AcceptChanges();
}
orders.AcceptChanges();
The code above doesn't do anything!

This is because of two things:

1. you did not call updateSqlData(orders), or whatever you have as
an updating counterpart to getSqlData, and

2. you don't need AcceptChanges() after modifying the rows, this will
reset row states to 'unchanded' and therefore the rows will be skipped
during update.

 
C

Cor Ligthert [MVP]

Arne,

Can you try not to reformulate your messages.

Now I have answered a messages new while they where already answered.

Just go on in the same thread. You see that you get than responses as well.

Thanks in advance

Cor

Arne Garvander said:
I have reformulated my problem in a separate post.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Marina Levit said:
This is the reason you can't post messages that just say 'this doesn't do
anything' or 'this doesn't work'.

How are we supposed to know what you are trying to do, and what you
expect
to happen?

In any case, is the datatable already bound to the gridview? When are you
doing these updates? Is there a postback? What is happening here?

I am guessing that you are not rebinding to the gridview or something
similar related to timing, and thus it still shows the previous values
due
to viewstate. It's really hard to say since you provided no context for
your code.

message
I don't want to update the database. I want to see my changes in a
gridview.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


:

Arne Garvander wrote:
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows.BeginEdit();
orders.Rows[8]= 800 ;
orders.Rows.EndEdit();
orders.Rows.AcceptChanges();
}
orders.AcceptChanges();
The code above doesn't do anything!

This is because of two things:

1. you did not call updateSqlData(orders), or whatever you have as
an updating counterpart to getSqlData, and

2. you don't need AcceptChanges() after modifying the rows, this will
reset row states to 'unchanded' and therefore the rows will be skipped
during update.

 
G

Guest

If my question is dumb I will only get dumb answers. I need to properly
formulate my question to a useful answer.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Cor Ligthert said:
Arne,

Can you try not to reformulate your messages.

Now I have answered a messages new while they where already answered.

Just go on in the same thread. You see that you get than responses as well.

Thanks in advance

Cor

Arne Garvander said:
I have reformulated my problem in a separate post.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Marina Levit said:
This is the reason you can't post messages that just say 'this doesn't do
anything' or 'this doesn't work'.

How are we supposed to know what you are trying to do, and what you
expect
to happen?

In any case, is the datatable already bound to the gridview? When are you
doing these updates? Is there a postback? What is happening here?

I am guessing that you are not rebinding to the gridview or something
similar related to timing, and thus it still shows the previous values
due
to viewstate. It's really hard to say since you provided no context for
your code.

message
I don't want to update the database. I want to see my changes in a
gridview.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


:

Arne Garvander wrote:
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows.BeginEdit();
orders.Rows[8]= 800 ;
orders.Rows.EndEdit();
orders.Rows.AcceptChanges();
}
orders.AcceptChanges();
The code above doesn't do anything!

This is because of two things:

1. you did not call updateSqlData(orders), or whatever you have as
an updating counterpart to getSqlData, and

2. you don't need AcceptChanges() after modifying the rows, this will
reset row states to 'unchanded' and therefore the rows will be skipped
during update.

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top