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 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
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 .
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
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 > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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";...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
| |