473,587 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update query in DataTable??

Hi,

I want to know if there is an easy way to do update a column of a row in
DataTable.
Nov 17 '05 #1
8 14820
ZeroVisio,

If you mean to the back end data source that the data came from, no,
there is not. You will have to create a data adapter that will update the
table appropriately, and make sure that the table only has the change on
that one row. Once you have that, you can run it through the data adapter,
and the data on the back end should be updated.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"ZeroVisio" <Ze*******@disc ussions.microso ft.com> wrote in message
news:3F******** *************** ***********@mic rosoft.com...
Hi,

I want to know if there is an easy way to do update a column of a row in
DataTable.

Nov 17 '05 #2
Nicholas,

thanks for the reply. I want to just update the dataTable. in my case I'm
not using datatable for getting data from any database. it is just a
dataholder (i found it easy to use datatable than two dimensional dynamic
array for searching certain elements in it).
So how do you it. I saw there is something like acceptChanges but I couldn't
figure how to make changes! Help!!

"Nicholas Paldino [.NET/C# MVP]" wrote:
ZeroVisio,

If you mean to the back end data source that the data came from, no,
there is not. You will have to create a data adapter that will update the
table appropriately, and make sure that the table only has the change on
that one row. Once you have that, you can run it through the data adapter,
and the data on the back end should be updated.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"ZeroVisio" <Ze*******@disc ussions.microso ft.com> wrote in message
news:3F******** *************** ***********@mic rosoft.com...
Hi,

I want to know if there is an easy way to do update a column of a row in
DataTable.


Nov 17 '05 #3
ZeroVisio,

But where do you want to make the changes to? Do you just want to
commit them to the DataTable in memory? If that is the case, calling
AcceptChanges will just make it so that the state of each row is unchanged.
Basically, adds, edits, and deletes will be committed (there will not be an
original row version).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"ZeroVisio" <Ze*******@disc ussions.microso ft.com> wrote in message
news:3E******** *************** ***********@mic rosoft.com...
Nicholas,

thanks for the reply. I want to just update the dataTable. in my case I'm
not using datatable for getting data from any database. it is just a
dataholder (i found it easy to use datatable than two dimensional dynamic
array for searching certain elements in it).
So how do you it. I saw there is something like acceptChanges but I
couldn't
figure how to make changes! Help!!

"Nicholas Paldino [.NET/C# MVP]" wrote:
ZeroVisio,

If you mean to the back end data source that the data came from, no,
there is not. You will have to create a data adapter that will update
the
table appropriately, and make sure that the table only has the change on
that one row. Once you have that, you can run it through the data
adapter,
and the data on the back end should be updated.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"ZeroVisio" <Ze*******@disc ussions.microso ft.com> wrote in message
news:3F******** *************** ***********@mic rosoft.com...
> Hi,
>
> I want to know if there is an easy way to do update a column of a row
> in
> DataTable.


Nov 17 '05 #4
yaah i just want to commit changes to datatable in memory. righnow i dont
intend to write this table to any database (but maybe in future if it is
needed). here is exactly what im trying to do.

i have seven columns and some rows in my datatable: here is my snapshot of
datatable

id, type,text, start, end, st_flg, end_flg
3, Strategy , pmts, 1, 2, N, N
5, Strategy , print, 1, 4, N, N
7, Strategy, Mail, 1, 6, N, N

now after checking a condiition i want to change N to Y in st_flg and/or
end_flg.

so I retrieve rows that match my criteria and want to update the st_flg
and/or end_flg. However all this in memory. no final commitment to database.

i thought of using datarow.itemarr ay.setvalue but then dont know how this
will reflect back to my table.

hope you can help!


"Nicholas Paldino [.NET/C# MVP]" wrote:
ZeroVisio,

But where do you want to make the changes to? Do you just want to
commit them to the DataTable in memory? If that is the case, calling
AcceptChanges will just make it so that the state of each row is unchanged.
Basically, adds, edits, and deletes will be committed (there will not be an
original row version).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"ZeroVisio" <Ze*******@disc ussions.microso ft.com> wrote in message
news:3E******** *************** ***********@mic rosoft.com...
Nicholas,

thanks for the reply. I want to just update the dataTable. in my case I'm
not using datatable for getting data from any database. it is just a
dataholder (i found it easy to use datatable than two dimensional dynamic
array for searching certain elements in it).
So how do you it. I saw there is something like acceptChanges but I
couldn't
figure how to make changes! Help!!

"Nicholas Paldino [.NET/C# MVP]" wrote:
ZeroVisio,

If you mean to the back end data source that the data came from, no,
there is not. You will have to create a data adapter that will update
the
table appropriately, and make sure that the table only has the change on
that one row. Once you have that, you can run it through the data
adapter,
and the data on the back end should be updated.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"ZeroVisio" <Ze*******@disc ussions.microso ft.com> wrote in message
news:3F******** *************** ***********@mic rosoft.com...
> Hi,
>
> I want to know if there is an easy way to do update a column of a row
> in
> DataTable.


Nov 17 '05 #5
ZeroVisio,
The "easiest" way is to use a for each loop. Something like:

' Create a DataTable
DataTable table = new DataTable("Zero Visio");
table.Columns.A dd("id", typeof(int));
table.Columns.A dd("type", typeof(string)) ;
table.Columns.A dd("text", typeof(string)) ;
table.Columns.A dd("start", typeof(string)) ;
table.Columns.A dd("end", typeof(string)) ;
table.Columns.A dd("st_flg", typeof(char));
table.Columns.A dd("end_flg", typeof(char));

' Fill the DataTable
table.Rows.Add( new object[] {3, "Strategy", "pmts", 1, 2, 'N', 'N'}) ;
table.Rows.Add( new object[] {5, "Strategy", "print", 1, 4, 'N', 'N'}) ;
table.Rows.Add( new object[] {7, "Strategy", "Mail", 1, 6, 'N', 'N'}) ;

' Update table Set st_flg = 'Y'
foreach(DataRow row in table.Rows)
{
row["st_flg"] = 'Y';
}

You can use table.Select if you want to restrict to certain rows.

' Update table Set st_flg = 'Y' Where text = 'pmts'
foreach(DataRow row in table.Select("t ext = 'pmts'"))
{
row["end_flg"] = 'Y';
}

I don't have a sample handy, one could even generalize the above into a
callable routine.

Hope this helps
Jay

"ZeroVisio" <Ze*******@disc ussions.microso ft.com> wrote in message
news:3F******** *************** ***********@mic rosoft.com...
Hi,

I want to know if there is an easy way to do update a column of a row in
DataTable.

Nov 17 '05 #6
ZeroVisio,
The "easiest" way is to use a for each loop. Something like:

' Create a DataTable
DataTable table = new DataTable("Zero Visio");
table.Columns.A dd("id", typeof(int));
table.Columns.A dd("type", typeof(string)) ;
table.Columns.A dd("text", typeof(string)) ;
table.Columns.A dd("start", typeof(string)) ;
table.Columns.A dd("end", typeof(string)) ;
table.Columns.A dd("st_flg", typeof(char));
table.Columns.A dd("end_flg", typeof(char));

' Fill the DataTable
table.Rows.Add( new object[] {3, "Strategy", "pmts", 1, 2, 'N', 'N'}) ;
table.Rows.Add( new object[] {5, "Strategy", "print", 1, 4, 'N', 'N'}) ;
table.Rows.Add( new object[] {7, "Strategy", "Mail", 1, 6, 'N', 'N'}) ;

' Update table Set st_flg = 'Y'
foreach(DataRow row in table.Rows)
{
row["st_flg"] = 'Y';
}

You can use table.Select if you want to restrict to certain rows.

' Update table Set st_flg = 'Y' Where text = 'pmts'
foreach(DataRow row in table.Select("t ext = 'pmts'"))
{
row["end_flg"] = 'Y';
}

I don't have a sample handy, one could even generalize the above into a
callable routine.

Hope this helps
Jay

"ZeroVisio" <Ze*******@disc ussions.microso ft.com> wrote in message
news:3F******** *************** ***********@mic rosoft.com...
Hi,

I want to know if there is an easy way to do update a column of a row in
DataTable.

Nov 17 '05 #7
Hi Jay,

That was really helpful. I had datatow separately and thus wasnt able to
figure out how to reflect the changes back to the original DAtatable. It
works like a charm, thanks a zillion!!!

"Jay B. Harlow [MVP - Outlook]" wrote:
ZeroVisio,
The "easiest" way is to use a for each loop. Something like:

' Create a DataTable
DataTable table = new DataTable("Zero Visio");
table.Columns.A dd("id", typeof(int));
table.Columns.A dd("type", typeof(string)) ;
table.Columns.A dd("text", typeof(string)) ;
table.Columns.A dd("start", typeof(string)) ;
table.Columns.A dd("end", typeof(string)) ;
table.Columns.A dd("st_flg", typeof(char));
table.Columns.A dd("end_flg", typeof(char));

' Fill the DataTable
table.Rows.Add( new object[] {3, "Strategy", "pmts", 1, 2, 'N', 'N'}) ;
table.Rows.Add( new object[] {5, "Strategy", "print", 1, 4, 'N', 'N'}) ;
table.Rows.Add( new object[] {7, "Strategy", "Mail", 1, 6, 'N', 'N'}) ;

' Update table Set st_flg = 'Y'
foreach(DataRow row in table.Rows)
{
row["st_flg"] = 'Y';
}

You can use table.Select if you want to restrict to certain rows.

' Update table Set st_flg = 'Y' Where text = 'pmts'
foreach(DataRow row in table.Select("t ext = 'pmts'"))
{
row["end_flg"] = 'Y';
}

I don't have a sample handy, one could even generalize the above into a
callable routine.

Hope this helps
Jay

"ZeroVisio" <Ze*******@disc ussions.microso ft.com> wrote in message
news:3F******** *************** ***********@mic rosoft.com...
Hi,

I want to know if there is an easy way to do update a column of a row in
DataTable.


Nov 17 '05 #8
Hi Jay,

That was really helpful. I had datatow separately and thus wasnt able to
figure out how to reflect the changes back to the original DAtatable. It
works like a charm, thanks a zillion!!!

"Jay B. Harlow [MVP - Outlook]" wrote:
ZeroVisio,
The "easiest" way is to use a for each loop. Something like:

' Create a DataTable
DataTable table = new DataTable("Zero Visio");
table.Columns.A dd("id", typeof(int));
table.Columns.A dd("type", typeof(string)) ;
table.Columns.A dd("text", typeof(string)) ;
table.Columns.A dd("start", typeof(string)) ;
table.Columns.A dd("end", typeof(string)) ;
table.Columns.A dd("st_flg", typeof(char));
table.Columns.A dd("end_flg", typeof(char));

' Fill the DataTable
table.Rows.Add( new object[] {3, "Strategy", "pmts", 1, 2, 'N', 'N'}) ;
table.Rows.Add( new object[] {5, "Strategy", "print", 1, 4, 'N', 'N'}) ;
table.Rows.Add( new object[] {7, "Strategy", "Mail", 1, 6, 'N', 'N'}) ;

' Update table Set st_flg = 'Y'
foreach(DataRow row in table.Rows)
{
row["st_flg"] = 'Y';
}

You can use table.Select if you want to restrict to certain rows.

' Update table Set st_flg = 'Y' Where text = 'pmts'
foreach(DataRow row in table.Select("t ext = 'pmts'"))
{
row["end_flg"] = 'Y';
}

I don't have a sample handy, one could even generalize the above into a
callable routine.

Hope this helps
Jay

"ZeroVisio" <Ze*******@disc ussions.microso ft.com> wrote in message
news:3F******** *************** ***********@mic rosoft.com...
Hi,

I want to know if there is an easy way to do update a column of a row in
DataTable.


Nov 17 '05 #9

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

Similar topics

3
7025
by: Bill Clark | last post by:
I have about 20,000 records pulled from Excel that I need to update. What I need to do is run an update query that bascially says: If a field is null, update it with the previous record value of that same field. In some instances, it will have to go back a few records before it finds a value that is not null. Can this be done? Thanks ...
5
13208
by: Don Seckler | last post by:
I have an update query that runs when a report closes. I have several reports that will need to run the update query with diferent criteria. I'd like to simply make the criteria change in the report vba instead of making different queries. Here's my query sql: UPDATE Draw SET Draw.Billed = Yes WHERE (((Draw.Billed)=No) AND...
10
3260
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This wouldn't work (nothing changed): UPDATE tblManuals SET tblManuals.PARTNUM = Trim(); Would someone please tell me how to do an update query that will...
4
11323
by: deko | last post by:
I'm trying to update the address record of an existing record in my mdb with values from another existing record in the same table. In pseudo code it might look like this: UPDATE tblAddress SET AddressDescription of Entity 456 = AddressDescription of Entity_ID 123 Address1 of Entity 456 = Address1 of Entity_ID 123 City of Entity 456 =...
7
3524
by: Mark Carlyle via AccessMonster.com | last post by:
I have this update query that I am trying to run. I know the syntax is messed up but do not know how to correct it. Select 'UPDATE', Transactions,'Set = where = ' From "Get Daily Balances" Transactions = name of the table I want to update balance = name of the field i want to update daily balance= name of the query result that I want...
2
5058
by: bobabooey2k | last post by:
I have an update query with one field having in its "Update to" cell a DLookup statement. This query takes 2-3 minutes on 3000 records. Can I avoid dlookup here using multiple queries? An underlying subquery to this Update query involves a MAX function on a date field, which is then used in the DLookup statement. Any help appreciated....
4
11154
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 call the following method. public void JobListDataTableFromAccessCommitChange() { System.Data.DataTable oChangeDataTable;
1
12114
by: Tim Kelley | last post by:
I need to loop through a datatable and update a particular field. This seems like it should be fairly easy but it is giving me fits. Here is the code that I have so far. foreach (DataRow row in dataTable.Rows) { row = "xyz";
0
1592
by: Hurricane | last post by:
I have my SQL database with a table that I am trying to have a gridview dislay with inline editing. It seems as if the dataset does not generate the apropriate update query, and therefore consequently the gridview does not automatically allow editing. I then try to change which update query that is selected being the dataRow,...
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.