473,320 Members | 2,098 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,320 software developers and data experts.

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 14791
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.com

"ZeroVisio" <Ze*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.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.com

"ZeroVisio" <Ze*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.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.com

"ZeroVisio" <Ze*******@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.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.com

"ZeroVisio" <Ze*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.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.itemarray.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.com

"ZeroVisio" <Ze*******@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.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.com

"ZeroVisio" <Ze*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.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("ZeroVisio");
table.Columns.Add("id", typeof(int));
table.Columns.Add("type", typeof(string));
table.Columns.Add("text", typeof(string));
table.Columns.Add("start", typeof(string));
table.Columns.Add("end", typeof(string));
table.Columns.Add("st_flg", typeof(char));
table.Columns.Add("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("text = '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*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.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("ZeroVisio");
table.Columns.Add("id", typeof(int));
table.Columns.Add("type", typeof(string));
table.Columns.Add("text", typeof(string));
table.Columns.Add("start", typeof(string));
table.Columns.Add("end", typeof(string));
table.Columns.Add("st_flg", typeof(char));
table.Columns.Add("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("text = '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*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.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("ZeroVisio");
table.Columns.Add("id", typeof(int));
table.Columns.Add("type", typeof(string));
table.Columns.Add("text", typeof(string));
table.Columns.Add("start", typeof(string));
table.Columns.Add("end", typeof(string));
table.Columns.Add("st_flg", typeof(char));
table.Columns.Add("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("text = '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*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.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("ZeroVisio");
table.Columns.Add("id", typeof(int));
table.Columns.Add("type", typeof(string));
table.Columns.Add("text", typeof(string));
table.Columns.Add("start", typeof(string));
table.Columns.Add("end", typeof(string));
table.Columns.Add("st_flg", typeof(char));
table.Columns.Add("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("text = '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*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.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
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...
5
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...
10
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...
4
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...
7
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" ...
2
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...
4
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...
1
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...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.