473,387 Members | 1,464 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,387 software developers and data experts.

Clone DataTable or Copy DataTable Problem

Hi All,

Due to can't insert new row between row and row while current
DataTable looping.
In order to solve the problem, I need to clone it as new DataTable,
while the DataTable Looping, it also insert both of new row and
existing datarow into new DataTable, but I don't know how to do that,
Here is my souce code, Please advise.

if ( myTable.Rows.Count > 0 )
{
msg.Text = "";

y = myTable.Rows.Count;

for (i=0; y > i ; i++ )
{

DataRow dataRow = myTable.Rows[i];

if ((Convert.ToString(myOrderNo) == "") ||
(Convert.ToString(myOrderNo) == null))
{
myOrderNo = Convert.ToString(dataRow["OrderNo"]);
}

if (myOrderNo != Convert.ToString(dataRow["OrderNo"]))
{
// DataRowCollection rc = myTable.Rows;
mySubTotal = Convert.ToDouble(myTotalPrice) - (
Convert.ToDouble(myTotalPrice) *
Convert.ToInt16(dataRow["HeadDiscount"]) /100 );

dr1 = myTable.NewRow();
dr1["OrderNo"] = myOrderNo;
dr1["TotalPrice"] = Convert.ToDouble(mySubTotal);

// myTable.Rows.Add(dr1);
myTable.Rows.InsertAt(dr1,i);
myTable.AcceptChanges();

myGrandTotal = Convert.ToDouble(myGrandTotal) +
Convert.ToDouble(mySubTotal);
myOrderNo = Convert.ToString(dataRow["OrderNo"]);

myTotalPrice = 0;
}
myTotalPrice = myTotalPrice +
Convert.ToDouble(dataRow["TotalPrice"]);

// Add Last Record
if (y == i + 1)
{
DataRowCollection rc = myTable.Rows;
mySubTotal = Convert.ToDouble(myTotalPrice) - (
Convert.ToDouble(myTotalPrice) *
Convert.ToInt16(dataRow["HeadDiscount"]) /100 );

dr1 = myTable.NewRow();
dr1["OrderNo"] = myOrderNo;
dr1["TotalPrice"] = Convert.ToDouble(mySubTotal);

//myTable.Rows.Add(dr1);
myTable.Rows.InsertAt(dr1,i);
myTable.AcceptChanges();

myGrandTotal = Convert.ToDouble(myGrandTotal) +
Convert.ToDouble(mySubTotal);
}

}
Nov 16 '05 #1
0 5808

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

Similar topics

0
by: Jason Evans | last post by:
Hi All, I am writing my own implementation of queue via a linked list, note not a LinkedList, and was running into trouble with the clone method. I was wondering if anyone could point out some...
4
by: Vincent | last post by:
Hey, I have a problem to understand the underlaying of clone method. Hope someone can help me out. Let's say, clonedObject = originalObject.clone() (syntax may be wrong, but you know what I...
6
by: Steve | last post by:
I can't find a straight answer on what to use? I need a deep copy, so I implemented IConeable and the Clone() method. However, I'm not sure I did it correct. Is it suposed to be an allocation of...
2
by: Danny Ni | last post by:
Hi, I would like to know the fastest way to clone a dataset with filter inVB.Net or C#. Say I have a dataset that has one datatable having several data rows. I want to clone the structure to...
2
by: Doug Bell | last post by:
Hi, I am trying to clone a DataRow (see below) but I have a syntax error refering to the implicit conversion from object to datarow. How can I convert the object into a datarow without...
4
by: csharpula csharp | last post by:
Hello, Have a basic question about Clone() If I am using the clone method on some object ,are the Cloned object properties going to change at every property change in original object? Thanks! ...
5
by: DavidB | last post by:
I have a situation where a user needs to clone an existing BE database (stored on a server) to his local machine. Assume the followings... User goes into the database FE which has linked BE. ...
4
nev
by: nev | last post by:
I have a datatable dtt1 with data in it. It is bind to bs1 Then I do... dtt2 = dtt1.copy Thinking that I will be able to manipulate dtt2 without affecting dtt1... I assign a bindingsource...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...

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.