473,554 Members | 2,865 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about DataTable

Hi,

If I want to programatically add rows to a DataTable, do I call
AcceptChanges per row? Or do I call AcceptChanges after all rows added?

TIA
Jan 21 '06 #1
6 1692
Hello Danny,

That really depends on the scenario. If you add a lot of rows and will use
the dataadapter to persist them to the databse, don't call AcceptChanges
until you done just that.

da.Update(dt)
dt.AcceptChange s();

AcceptChanges will effectivly reset the state flag for each row to indicate
that it hasn't changed.
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net
Hi,

If I want to programatically add rows to a DataTable, do I call
AcceptChanges per row? Or do I call AcceptChanges after all rows
added?

TIA

Jan 21 '06 #2
Danny,

You don't have to call AcceptChanges.

If you call AcceptChanges, it will set the row state of the row to
unchanged. If you then pass this datatable to a data adapter, it will not
process the row when you try to update your back end data source.

If there is no back end data source, and you have no need for looking at
the row state, then that is fine.

When you are done, you can call AcceptChanges on the DataTable, and it
will make sure that AcceptChanges is called on all of the rows. If you have
a large number of rows in the table, you might want to call AcceptChanges on
each row as you add it (after creating it) through each iteration of your
loop, but that might be considered a premature optimization. You should
only do this if you find that making the call on the DataTable has proven to
be inefficient.

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

"Danny Ni" <dn**@yahoo.com > wrote in message
news:ek******** ******@tk2msftn gp13.phx.gbl...
Hi,

If I want to programatically add rows to a DataTable, do I call
AcceptChanges per row? Or do I call AcceptChanges after all rows added?

TIA

Jan 21 '06 #3
Nicholas,

Thank you for your response.

I am not clear about what you meant by : "pass this datatable to a data
adapter"

My understanding is:
DataAdapter adds a DataTable into a Dataset via da.Fill(ds,"myd t") method.
Then I can insert rows into the datatable and call da.Update method to save
data into backend server. In order for changes in a datatable to be saved to
backend, it must use the same DataAdapter that put it in Dataset.

Please elaborate and correct my confusion.

Thanks Again!

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Danny,

You don't have to call AcceptChanges.

If you call AcceptChanges, it will set the row state of the row to
unchanged. If you then pass this datatable to a data adapter, it will not
process the row when you try to update your back end data source.

If there is no back end data source, and you have no need for looking
at the row state, then that is fine.

When you are done, you can call AcceptChanges on the DataTable, and it
will make sure that AcceptChanges is called on all of the rows. If you
have a large number of rows in the table, you might want to call
AcceptChanges on each row as you add it (after creating it) through each
iteration of your loop, but that might be considered a premature
optimization. You should only do this if you find that making the call on
the DataTable has proven to be inefficient.

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

"Danny Ni" <dn**@yahoo.com > wrote in message
news:ek******** ******@tk2msftn gp13.phx.gbl...
Hi,

If I want to programatically add rows to a DataTable, do I call
AcceptChanges per row? Or do I call AcceptChanges after all rows added?

TIA


Jan 21 '06 #4
Danny,

Well, you don't necessarily have to use a data set that is filled with a
DataAdapter. As long as the structures match up with the various commands
in the adapter, it will work.

I was referring to the Update method. If you call AcceptChanges before
you pass your DataTable to the Update method, it will see the DataTable as
having no changes in it, and then it will do nothing.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Danny Ni" <dn**@yahoo.com > wrote in message
news:eR******** *****@TK2MSFTNG P11.phx.gbl...
Nicholas,

Thank you for your response.

I am not clear about what you meant by : "pass this datatable to a data
adapter"

My understanding is:
DataAdapter adds a DataTable into a Dataset via da.Fill(ds,"myd t") method.
Then I can insert rows into the datatable and call da.Update method to
save data into backend server. In order for changes in a datatable to be
saved to backend, it must use the same DataAdapter that put it in Dataset.

Please elaborate and correct my confusion.

Thanks Again!

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Danny,

You don't have to call AcceptChanges.

If you call AcceptChanges, it will set the row state of the row to
unchanged. If you then pass this datatable to a data adapter, it will
not process the row when you try to update your back end data source.

If there is no back end data source, and you have no need for looking
at the row state, then that is fine.

When you are done, you can call AcceptChanges on the DataTable, and it
will make sure that AcceptChanges is called on all of the rows. If you
have a large number of rows in the table, you might want to call
AcceptChanges on each row as you add it (after creating it) through each
iteration of your loop, but that might be considered a premature
optimization. You should only do this if you find that making the call
on the DataTable has proven to be inefficient.

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

"Danny Ni" <dn**@yahoo.com > wrote in message
news:ek******** ******@tk2msftn gp13.phx.gbl...
Hi,

If I want to programatically add rows to a DataTable, do I call
AcceptChanges per row? Or do I call AcceptChanges after all rows added?

TIA



Jan 21 '06 #5
I think I am clear about the AcceptChanges now.

If you don't mind, I would like to ask another question:
If I have a DataTable not filled into a DataSet by a DataAdapter, how do I
persist changes of this DataTable to backend?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:Ou******** ******@TK2MSFTN GP15.phx.gbl...
Danny,

Well, you don't necessarily have to use a data set that is filled with
a DataAdapter. As long as the structures match up with the various
commands in the adapter, it will work.

I was referring to the Update method. If you call AcceptChanges before
you pass your DataTable to the Update method, it will see the DataTable as
having no changes in it, and then it will do nothing.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Danny Ni" <dn**@yahoo.com > wrote in message
news:eR******** *****@TK2MSFTNG P11.phx.gbl...
Nicholas,

Thank you for your response.

I am not clear about what you meant by : "pass this datatable to a data
adapter"

My understanding is:
DataAdapter adds a DataTable into a Dataset via da.Fill(ds,"myd t")
method. Then I can insert rows into the datatable and call da.Update
method to save data into backend server. In order for changes in a
datatable to be saved to backend, it must use the same DataAdapter that
put it in Dataset.

Please elaborate and correct my confusion.

Thanks Again!

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Danny,

You don't have to call AcceptChanges.

If you call AcceptChanges, it will set the row state of the row to
unchanged. If you then pass this datatable to a data adapter, it will
not process the row when you try to update your back end data source.

If there is no back end data source, and you have no need for looking
at the row state, then that is fine.

When you are done, you can call AcceptChanges on the DataTable, and
it will make sure that AcceptChanges is called on all of the rows. If
you have a large number of rows in the table, you might want to call
AcceptChanges on each row as you add it (after creating it) through each
iteration of your loop, but that might be considered a premature
optimization. You should only do this if you find that making the call
on the DataTable has proven to be inefficient.

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

"Danny Ni" <dn**@yahoo.com > wrote in message
news:ek******** ******@tk2msftn gp13.phx.gbl...
Hi,

If I want to programatically add rows to a DataTable, do I call
AcceptChanges per row? Or do I call AcceptChanges after all rows added?

TIA



Jan 21 '06 #6
Danny,

You can add rows and set values on the data table yourself. For adds,
you just add the new row. For edits and deletes, you would have to create
the row in the data table, and then call AcceptChanges on the ROW. Once you
do that, you would have to delete the row or change a value in the row so
that the state is set to delete or edit.

Then you can pass that to your data adapter.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Danny Ni" <dn**@yahoo.com > wrote in message
news:eh******** ******@TK2MSFTN GP14.phx.gbl...
I think I am clear about the AcceptChanges now.

If you don't mind, I would like to ask another question:
If I have a DataTable not filled into a DataSet by a DataAdapter, how do I
persist changes of this DataTable to backend?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in message news:Ou******** ******@TK2MSFTN GP15.phx.gbl...
Danny,

Well, you don't necessarily have to use a data set that is filled with
a DataAdapter. As long as the structures match up with the various
commands in the adapter, it will work.

I was referring to the Update method. If you call AcceptChanges
before you pass your DataTable to the Update method, it will see the
DataTable as having no changes in it, and then it will do nothing.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Danny Ni" <dn**@yahoo.com > wrote in message
news:eR******** *****@TK2MSFTNG P11.phx.gbl...
Nicholas,

Thank you for your response.

I am not clear about what you meant by : "pass this datatable to a data
adapter"

My understanding is:
DataAdapter adds a DataTable into a Dataset via da.Fill(ds,"myd t")
method. Then I can insert rows into the datatable and call da.Update
method to save data into backend server. In order for changes in a
datatable to be saved to backend, it must use the same DataAdapter that
put it in Dataset.

Please elaborate and correct my confusion.

Thanks Again!

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Danny,

You don't have to call AcceptChanges.

If you call AcceptChanges, it will set the row state of the row to
unchanged. If you then pass this datatable to a data adapter, it will
not process the row when you try to update your back end data source.

If there is no back end data source, and you have no need for
looking at the row state, then that is fine.

When you are done, you can call AcceptChanges on the DataTable, and
it will make sure that AcceptChanges is called on all of the rows. If
you have a large number of rows in the table, you might want to call
AcceptChanges on each row as you add it (after creating it) through
each iteration of your loop, but that might be considered a premature
optimization. You should only do this if you find that making the call
on the DataTable has proven to be inefficient.

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

"Danny Ni" <dn**@yahoo.com > wrote in message
news:ek******** ******@tk2msftn gp13.phx.gbl...
> Hi,
>
> If I want to programatically add rows to a DataTable, do I call
> AcceptChanges per row? Or do I call AcceptChanges after all rows
> added?
>
> TIA
>



Jan 21 '06 #7

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

Similar topics

3
1391
by: Bruno Rodrigues | last post by:
Hi all I'm using the following code standart in class libraries. I will not split this function in more layers, but I want to know if there are some architetural improvement to do in my code. E.g: Database connection; Try/Catch use; DataTable as a set of rows; etc... Any suggestions are welcome. Thanks!
10
2937
by: Shawn Meyer | last post by:
Hello - I am trying to write a class that has an async BeginX and EndX, plus the regular X syncronous method. Delegates seemed like the way to go, however, I still am having problems getting exactly what I want. Here are my goals 1. I would like the IAsyncResult that is returned by the Begin function to be able to be waited on or...
1
2629
by: M | last post by:
My problem is that AutogenerateColumns="false" does not work with the datatable I built from a hashtable. (Please don't ask why I'm pulling data from a database, putting it in a hashtable, then putting it into a datatable.) Everything works great, including hiding the column on the fly. Problem is, the rest of the datatable data/columns still...
3
1017
by: simon | last post by:
I have one question. DataGrid control is performance cost.Use any other control if possible. That is by the book. But I need sorting and paging on all my pages. So, is there any better solution or I should use dataGrid anyway? Thank you, Simon
4
1288
by: angus | last post by:
Dear All, in my asp.net, i have - a textbox to input a text - a "add row" button, after it has been clicked the text in the textbox will add to the table - a submit button, the user can add a lot of the rows until submit button is pressed. during that, the data added in the table will be insert into the database
1
1918
by: kempshall | last post by:
Hi, I have a question about the .NET DataTable.ImportRow method. If I import a DataRow into an empty DataTable, will the empty DataTable pick up the schema of the DataRow I'm trying to put into it? For example, I have code that looks like this: DataTable tableWithData; DataTable emptyTable = new DataTable();...
2
1915
by: Asfar | last post by:
Hi, I have a VS2005 windows program written in c#. In this program I have an array list which stores many DataTable's. When I first run the pogram the arraylist is loaded with datatables. At this point when the see the memory used by the program in task manager it is 135,654K. Now when I minimize the application the memory goes down to...
5
5885
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to store a DataTable in any other way outside of our servers. In doing so, we leave ourselves open to large memory requirements. Furthermore, most web...
0
1134
Sl1ver
by: Sl1ver | last post by:
Hi Doesn't the grid that you create, create its own datatable that you can use in the program, meaning for a update code that i want to use with my datagrid i need a datable, but that means i have to create dataset and sql queries and everything, doesn't the grid have the sql queries already? private void...
0
7573
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
7496
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
8008
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7857
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6114
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
5412
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
3538
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
3525
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.