473,395 Members | 1,571 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,395 software developers and data experts.

DatTables

I have a System.Data.DataTable in memory in which I would like to change the
value of a column for all rows. Is there a method to change all rows to a
specified value?

I know I can loop thru all the records (see below), but I would like to
update the datatable with 1 statement, perhaps an sql update statement? It
would also be useful if I can run an sql update statement on a datatable in
memory, instead of looping.

foreach (System.Data.DataRow row in System.Data.DataTable)
{
row["MyColumn"] = 0; // There has to be better way, then
to loop.....
}
Thanks,
Steve

Nov 15 '05 #1
4 3104
Hi Steve,

AFAIK that is not only the best way but the only :)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Steve Bezner" <sb*****@softhome.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a System.Data.DataTable in memory in which I would like to change the value of a column for all rows. Is there a method to change all rows to a
specified value?

I know I can loop thru all the records (see below), but I would like to
update the datatable with 1 statement, perhaps an sql update statement? It would also be useful if I can run an sql update statement on a datatable in memory, instead of looping.

foreach (System.Data.DataRow row in System.Data.DataTable)
{
row["MyColumn"] = 0; // There has to be better way, then
to loop.....
}
Thanks,
Steve

Nov 15 '05 #2
Well... I would do it that way also!!

Cheers...
Mariano
-----Original Message-----
I have a System.Data.DataTable in memory in which I would like to change thevalue of a column for all rows. Is there a method to change all rows to aspecified value?

I know I can loop thru all the records (see below), but I would like toupdate the datatable with 1 statement, perhaps an sql update statement? Itwould also be useful if I can run an sql update statement on a datatable inmemory, instead of looping.

foreach (System.Data.DataRow row in System.Data.DataTable)
{
row["MyColumn"] = 0; // There has to be better way, thento loop.....
}
Thanks,
Steve

.

Nov 15 '05 #3
Thanks.

So what your saying if I want to update all records based on a certain
condition, then I would have to loop thru each record and check for the
condition before changing. It would be nice if I could pass an sql update
statement. Looping and checking sounds expensive.

Thanks for your response,
Steve
"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
Hi Steve,

AFAIK that is not only the best way but the only :)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Steve Bezner" <sb*****@softhome.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have a System.Data.DataTable in memory in which I would like to change

the
value of a column for all rows. Is there a method to change all rows to a specified value?

I know I can loop thru all the records (see below), but I would like to
update the datatable with 1 statement, perhaps an sql update statement?

It
would also be useful if I can run an sql update statement on a datatable

in
memory, instead of looping.

foreach (System.Data.DataRow row in System.Data.DataTable)
{
row["MyColumn"] = 0; // There has to be better way, then to loop.....
}
Thanks,
Steve


Nov 15 '05 #4
Thanks. I didn't want to have to get into transactions, because these are
changes that may need to be rolled back. It would have been nice if MSFT
implemented more of the "engine" as they did with the select statement.


"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
Hi Steve,

Please remember that the classes of ADO.NET are mean to be an in memory
representation of a DB, they are not intended to work as a SQL engine.
If you are going to replace all the rows in a datatable, well it's better
that you call a SP in the database and replace the table with the new data
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Steve Bezner" <sb*****@softhome.net> wrote in message
news:eX**************@TK2MSFTNGP12.phx.gbl...
Thanks.

So what your saying if I want to update all records based on a certain
condition, then I would have to loop thru each record and check for the
condition before changing. It would be nice if I could pass an sql update
statement. Looping and checking sounds expensive.

Thanks for your response,
Steve
"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
Hi Steve,

AFAIK that is not only the best way but the only :)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Steve Bezner" <sb*****@softhome.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> I have a System.Data.DataTable in memory in which I would like to change the
> value of a column for all rows. Is there a method to change all
rows to
a
> specified value?
>
> I know I can loop thru all the records (see below), but I would like to > update the datatable with 1 statement, perhaps an sql update statement? It
> would also be useful if I can run an sql update statement on a datatable in
> memory, instead of looping.
>
> foreach (System.Data.DataRow row in System.Data.DataTable)
> {
> row["MyColumn"] = 0; // There has to be better

way, then
> to loop.....
> }
>
>
> Thanks,
> Steve
>
>
>



Nov 15 '05 #5

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

Similar topics

1
by: Stijn Goris | last post by:
Hi all, I have 3 Comboboxes i want to bind with 3 different DatTables. I use this.cbxProductCategory.DataSource = myDataTable; this.cbxProductCategory.DisplayMember = "PTCA_DESCR";...
4
by: dhpacheco | last post by:
Hello I’m doing an application using VS 2005, c# for management a DB, but I new using the language, neither have experience in programming. Please could someone tell me if this is correct? I...
3
by: =?Utf-8?B?TWFydGluIEtvY2g=?= | last post by:
1st I serialize a DataSet (contains 14 DataTables) into file, with BinaryFormatter. 2nd I change some columns in a DataTable. 3rd When I now Deserialize the DataSet from bin file got I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.