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 6 1699
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
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
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
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
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
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 >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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!
|
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 polled to check for completion.
2. The Begin function would take a callback, and the async process would
|
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 prints out in the
datagrid via autogeneration. So I have duplicate columns....the ones I...
|
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
|
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
| |
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();
emptyTable.ImportRow(tableWithData.Rows);
|
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 1,456K. Again
when I maximize the program and start using different menu options the
memory used...
|
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 pages do not
really support multiple changes per transaction. In other words, when
the user submits...
|
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 gridControl1_EmbeddedNavigator_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Do you...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |