How can I update a datatable?

G

Guest

One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes to
column 8 doesn't show in my gridview! Changes made with an itemtemplate works
just fine.
 
G

Guest

I am calling my code from page_load after a postback.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


W.G. Ryan - MVP said:
Set the Expression property of a new datacolumn to do the computation for
you. As far as showing up goes, that's been the subject of many other posts
so until I know what events your doing this in, i can't be of much help.
http://www.knowdotnet.com/articles/dataviews1.html
Arne Garvander said:
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.
 
M

Marina Levit [MVP]

Actually, this is a change to column 9, since it starts out with a 0 based
index.

This sort of code does work - and I've used it before.

If you are using 1.1, are you recompiling your project? Are you running
locally, or uploading elsewhere - in which case, are you uploading all the
right files?

Have you actually steppped through this with the debugger to confirm that
the right cell is being modified?

I think you are doing something else that is causing the data to not show up
as you expect. Or, maybe you are looking in the wrong column. Or maybe you
are somehow accidentally hiding this column being computed.

The Expression mechanism mechanismz W.G. Ryan mentioned is a good way to
have arbitrary calculations done, without having to do them yourself on
every row.

Lastly, you don't need to post 5 times, with the same message, over and
over. You've already been asked several times to keep it in the thread.
Sooner or later people are going to stop responding to your posts
altogether.
 
G

Guest

The expression feature doesn't solve my problem.
I need to be able to recompute one column on a line by line basis.

--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


W.G. Ryan - MVP said:
Set the Expression property of a new datacolumn to do the computation for
you. As far as showing up goes, that's been the subject of many other posts
so until I know what events your doing this in, i can't be of much help.
http://www.knowdotnet.com/articles/dataviews1.html
Arne Garvander said:
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.
 
G

Guest

I have to repost my question, because so far no one has understood why I am
trying to do. Everyone tries to help with something that I don't want to
accomplish.
I thought I was expressing my question wrong.

--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Marina Levit said:
Actually, this is a change to column 9, since it starts out with a 0 based
index.

This sort of code does work - and I've used it before.

If you are using 1.1, are you recompiling your project? Are you running
locally, or uploading elsewhere - in which case, are you uploading all the
right files?

Have you actually steppped through this with the debugger to confirm that
the right cell is being modified?

I think you are doing something else that is causing the data to not show up
as you expect. Or, maybe you are looking in the wrong column. Or maybe you
are somehow accidentally hiding this column being computed.

The Expression mechanism mechanismz W.G. Ryan mentioned is a good way to
have arbitrary calculations done, without having to do them yourself on
every row.

Lastly, you don't need to post 5 times, with the same message, over and
over. You've already been asked several times to keep it in the thread.
Sooner or later people are going to stop responding to your posts
altogether.

Arne Garvander said:
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.
 
W

W.G. Ryan - MVP

Arne Garvander said:
The expression feature doesn't solve my problem.
I need to be able to recompute one column on a line by line basis.
Expressions do it on a line by line basis. And if you need it on with some
lines and off with others, you can modify the expression to handle that.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


W.G. Ryan - MVP said:
Set the Expression property of a new datacolumn to do the computation for
you. As far as showing up goes, that's been the subject of many other
posts
so until I know what events your doing this in, i can't be of much help.
http://www.knowdotnet.com/articles/dataviews1.html
message
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes
to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.
 
W

W.G. Ryan - MVP

so in page_load you have this code snippet that's fired every time? Do you
have another event that might be overwriting the changes? I"m assuming that
you've already checked the number of rows you're getting from the db to
ensure that's not the problem? (or if it's not coming from a db, just
checking Rows.Count?)
Arne Garvander said:
I am calling my code from page_load after a postback.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


W.G. Ryan - MVP said:
Set the Expression property of a new datacolumn to do the computation for
you. As far as showing up goes, that's been the subject of many other
posts
so until I know what events your doing this in, i can't be of much help.
http://www.knowdotnet.com/articles/dataviews1.html
message
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes
to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.
 
M

Marina Levit [MVP]

Maybe it is because you ignore the questions everyone is asking? It takes
asking you the same question 5 times before you will answer it.

I asked about 5, and you didn't respond to a single one.

Most of your posts have been exactly the same, with minimal new information
in each one. They weren't worth reposting, because you weren't providing
any more information then in the first one.

Arne Garvander said:
I have to repost my question, because so far no one has understood why I am
trying to do. Everyone tries to help with something that I don't want to
accomplish.
I thought I was expressing my question wrong.

--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Marina Levit said:
Actually, this is a change to column 9, since it starts out with a 0
based
index.

This sort of code does work - and I've used it before.

If you are using 1.1, are you recompiling your project? Are you running
locally, or uploading elsewhere - in which case, are you uploading all
the
right files?

Have you actually steppped through this with the debugger to confirm that
the right cell is being modified?

I think you are doing something else that is causing the data to not show
up
as you expect. Or, maybe you are looking in the wrong column. Or maybe
you
are somehow accidentally hiding this column being computed.

The Expression mechanism mechanismz W.G. Ryan mentioned is a good way to
have arbitrary calculations done, without having to do them yourself on
every row.

Lastly, you don't need to post 5 times, with the same message, over and
over. You've already been asked several times to keep it in the thread.
Sooner or later people are going to stop responding to your posts
altogether.

message
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes
to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.
 
G

Guest

I need to be to set the value of a specific column depending on the value of
the previous row. I don't think an expression would know anything about the
previous row. Once I am able to change anything at all in a column, then I
will build the logic that will compare values from different rows. I need a
sequence number for a subset of rows. If my subset is only one row than my
sequence number will be blank.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


W.G. Ryan - MVP said:
Arne Garvander said:
The expression feature doesn't solve my problem.
I need to be able to recompute one column on a line by line basis.
Expressions do it on a line by line basis. And if you need it on with some
lines and off with others, you can modify the expression to handle that.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


W.G. Ryan - MVP said:
Set the Expression property of a new datacolumn to do the computation for
you. As far as showing up goes, that's been the subject of many other
posts
so until I know what events your doing this in, i can't be of much help.
http://www.knowdotnet.com/articles/dataviews1.html
message
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes
to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.

 
G

Guest

I thought I had it working at another customer a few years ago. (in vb.net)
I you have it working, can you publish your code?
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Marina Levit said:
Actually, this is a change to column 9, since it starts out with a 0 based
index.

This sort of code does work - and I've used it before.

If you are using 1.1, are you recompiling your project? Are you running
locally, or uploading elsewhere - in which case, are you uploading all the
right files?

Have you actually steppped through this with the debugger to confirm that
the right cell is being modified?

I think you are doing something else that is causing the data to not show up
as you expect. Or, maybe you are looking in the wrong column. Or maybe you
are somehow accidentally hiding this column being computed.

The Expression mechanism mechanismz W.G. Ryan mentioned is a good way to
have arbitrary calculations done, without having to do them yourself on
every row.

Lastly, you don't need to post 5 times, with the same message, over and
over. You've already been asked several times to keep it in the thread.
Sooner or later people are going to stop responding to your posts
altogether.

Arne Garvander said:
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.
 
M

Marina Levit [MVP]

I don't have that exact code. I have updated rows in a datatable and then
bound them to an object, and seen the values I put in there.

Basically, you either need to start answering people's questions, or start
posting a complete, short reproduceable example.

Until then, all this is doing is going back and forth, with absolutely no
help from you to actually allow the people trying to help you to do so.
Until you are willing to actually willing to start answering the questions
you are asked and not just repost the exact same thing over and over,
personally, I feel like I can't help you and it is just wasting my time.

Good luck.

Arne Garvander said:
I thought I had it working at another customer a few years ago. (in
vb.net)
I you have it working, can you publish your code?
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Marina Levit said:
Actually, this is a change to column 9, since it starts out with a 0
based
index.

This sort of code does work - and I've used it before.

If you are using 1.1, are you recompiling your project? Are you running
locally, or uploading elsewhere - in which case, are you uploading all
the
right files?

Have you actually steppped through this with the debugger to confirm that
the right cell is being modified?

I think you are doing something else that is causing the data to not show
up
as you expect. Or, maybe you are looking in the wrong column. Or maybe
you
are somehow accidentally hiding this column being computed.

The Expression mechanism mechanismz W.G. Ryan mentioned is a good way to
have arbitrary calculations done, without having to do them yourself on
every row.

Lastly, you don't need to post 5 times, with the same message, over and
over. You've already been asked several times to keep it in the thread.
Sooner or later people are going to stop responding to your posts
altogether.

message
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes
to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.
 
G

Guest

I finally found my bug. I was confusing my column offset into my DataTable
with the column offset into my gridview. The column layout in my datatable
was not the same as the column layout in my gridview.
Thanks for your patience with a confused programmer.

--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Marina Levit said:
I don't have that exact code. I have updated rows in a datatable and then
bound them to an object, and seen the values I put in there.

Basically, you either need to start answering people's questions, or start
posting a complete, short reproduceable example.

Until then, all this is doing is going back and forth, with absolutely no
help from you to actually allow the people trying to help you to do so.
Until you are willing to actually willing to start answering the questions
you are asked and not just repost the exact same thing over and over,
personally, I feel like I can't help you and it is just wasting my time.

Good luck.

Arne Garvander said:
I thought I had it working at another customer a few years ago. (in
vb.net)
I you have it working, can you publish your code?
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Marina Levit said:
Actually, this is a change to column 9, since it starts out with a 0
based
index.

This sort of code does work - and I've used it before.

If you are using 1.1, are you recompiling your project? Are you running
locally, or uploading elsewhere - in which case, are you uploading all
the
right files?

Have you actually steppped through this with the debugger to confirm that
the right cell is being modified?

I think you are doing something else that is causing the data to not show
up
as you expect. Or, maybe you are looking in the wrong column. Or maybe
you
are somehow accidentally hiding this column being computed.

The Expression mechanism mechanismz W.G. Ryan mentioned is a good way to
have arbitrary calculations done, without having to do them yourself on
every row.

Lastly, you don't need to post 5 times, with the same message, over and
over. You've already been asked several times to keep it in the thread.
Sooner or later people are going to stop responding to your posts
altogether.

message
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes
to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.

 
W

W.G. Ryan - MVP

I've just whipped this up and it works exactly as advertised - how does
yours differ:

if (!Page.IsPostBack)

{

MainTable = new DataTable("ArnesTable");

DataColumn FirstColumn = new DataColumn("FirstColumn",
typeof(System.Int32));

DataColumn SecondColumn = new DataColumn("SecondColumn",
typeof(System.String));

MainTable.Columns.Add(FirstColumn);

MainTable.Columns.Add(SecondColumn);

DataRow dro = MainTable.NewRow();

dro[0] = 1;

dro[1] = "Bill";

MainTable.Rows.Add(dro);

dro = MainTable.NewRow();

dro[0] = 2;

dro[1] = "Arne";

MainTable.Rows.Add(dro);

dro = MainTable.NewRow();

dro[0] = 3;

dro[1] = "Marina";

MainTable.Rows.Add(dro);

MainTable.AcceptChanges();

Session["MainTable"] = MainTable;



}

else{

MainTable = Session["MainTable"] as DataTable;

foreach(DataRow dro in MainTable.Rows){

dro[0] = Convert.ToInt32(dro[0]) + 1;

}

}

GridView1.DataSource = MainTable;

GridView1.DataBind();

}
 
C

Cor Ligthert [MVP]

I finally found my bug. I was confusing my column offset into my DataTable
with the column offset into my gridview. The column layout in my datatable
was not the same as the column layout in my gridview.
Thanks for your patience with a confused programmer.
As I told you that could be the problem 8 hours ago.

Probably you did not even see it so many times have send in your messages
that you could not find them yourself anymore.

http://groups.google.com/group/microsoft.public.dotnet.framework.adonet/msg/741a6692f2f05de9


Cor

Arne Garvander said:
I finally found my bug. I was confusing my column offset into my DataTable
with the column offset into my gridview. The column layout in my datatable
was not the same as the column layout in my gridview.
Thanks for your patience with a confused programmer.

--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


Marina Levit said:
I don't have that exact code. I have updated rows in a datatable and
then
bound them to an object, and seen the values I put in there.

Basically, you either need to start answering people's questions, or
start
posting a complete, short reproduceable example.

Until then, all this is doing is going back and forth, with absolutely no
help from you to actually allow the people trying to help you to do so.
Until you are willing to actually willing to start answering the
questions
you are asked and not just repost the exact same thing over and over,
personally, I feel like I can't help you and it is just wasting my time.

Good luck.

message
I thought I had it working at another customer a few years ago. (in
vb.net)
I you have it working, can you publish your code?
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


:

Actually, this is a change to column 9, since it starts out with a 0
based
index.

This sort of code does work - and I've used it before.

If you are using 1.1, are you recompiling your project? Are you
running
locally, or uploading elsewhere - in which case, are you uploading all
the
right files?

Have you actually steppped through this with the debugger to confirm
that
the right cell is being modified?

I think you are doing something else that is causing the data to not
show
up
as you expect. Or, maybe you are looking in the wrong column. Or
maybe
you
are somehow accidentally hiding this column being computed.

The Expression mechanism mechanismz W.G. Ryan mentioned is a good way
to
have arbitrary calculations done, without having to do them yourself
on
every row.

Lastly, you don't need to post 5 times, with the same message, over
and
over. You've already been asked several times to keep it in the
thread.
Sooner or later people are going to stop responding to your posts
altogether.

message
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My
changes
to
column 8 doesn't show in my gridview! Changes made with an
itemtemplate
works
just fine.

 
G

Guest

The column layout in my datatable was not the same as the column layout in my
gridview, which confused me for a long time.
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


W.G. Ryan - MVP said:
I've just whipped this up and it works exactly as advertised - how does
yours differ:

if (!Page.IsPostBack)

{

MainTable = new DataTable("ArnesTable");

DataColumn FirstColumn = new DataColumn("FirstColumn",
typeof(System.Int32));

DataColumn SecondColumn = new DataColumn("SecondColumn",
typeof(System.String));

MainTable.Columns.Add(FirstColumn);

MainTable.Columns.Add(SecondColumn);

DataRow dro = MainTable.NewRow();

dro[0] = 1;

dro[1] = "Bill";

MainTable.Rows.Add(dro);

dro = MainTable.NewRow();

dro[0] = 2;

dro[1] = "Arne";

MainTable.Rows.Add(dro);

dro = MainTable.NewRow();

dro[0] = 3;

dro[1] = "Marina";

MainTable.Rows.Add(dro);

MainTable.AcceptChanges();

Session["MainTable"] = MainTable;



}

else{

MainTable = Session["MainTable"] as DataTable;

foreach(DataRow dro in MainTable.Rows){

dro[0] = Convert.ToInt32(dro[0]) + 1;

}

}

GridView1.DataSource = MainTable;

GridView1.DataBind();

}

Arne Garvander said:
One the columns in my gridview needs to be computed.
I am not able to get my computed value to stick.
DataTable orders;
getSqlData(orders);
for (i = 0; i < orders.Rows.Count; i++)
{
orders.Rows[8] = i * 8;
}
GridView1.DataSource = orders;
GridView1.DataBind();
How can I get a gridview control to display my computation? My changes to
column 8 doesn't show in my gridview! Changes made with an itemtemplate
works
just fine.
 

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