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

InsertAt Method Problem

Hi All,

I have some question about inserting new row into datatable.
I don't know why my all new rows inserted into end of datatable.
I am using myTable.Rows.InsertAt(dr, 0);

I don't know what is mean of the pos parameter. I also found problem
from MSDN.

row
The DataRow to add.
pos
The location in the collection where you want to add the DataRow.

If the value specified for the pos parameter is greater than the
number of rows in the collection, the new row is added to the end.

Please advise.
Nov 16 '05 #1
3 8753
Kelvin <ke*******@gmail.com> wrote:
I have some question about inserting new row into datatable.
I don't know why my all new rows inserted into end of datatable.
I am using myTable.Rows.InsertAt(dr, 0);

I don't know what is mean of the pos parameter. I also found problem
from MSDN.

row
The DataRow to add.
pos
The location in the collection where you want to add the DataRow.

If the value specified for the pos parameter is greater than the
number of rows in the collection, the new row is added to the end.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hi All,

I don't why I can't insert new rows between rows, and it can append on
buttom record of datatable. With reference my code, Using Rows.InserAt
or Rows.Add() is the better. Please advise.

// Define DataTable Format
DataRow dr2;
DataRow dr;
DataView myDataView;

if ( myTable.Rows.Count > 0 )
{
msg.Text = "";
y = myTable.Rows.Count;
for (i=0; i < y ; i++ )
{
DataRow dataRow = myTable.Rows[i];

if (myOrderNo != (String)dataRow["OrderNo"])
{
mySubTotal = Convert.ToDouble(myTotalPrice) - (Convert.ToDouble
(myTotalPrice) * (Convert.ToInt16(dataRow["HeadDiscount"])/100));
dr = myTable.NewRow();
DataRowCollection rc = myTable.Rows;
dr["CustNo"] = (String)dataRow["OrderNo"];
dr["TotalPrice"] = mySubTotal;
// myTable.Rows.InsertAt(dr,i);
myTable.Rows.Add(dr);
myTable.AcceptChanges();
myGrandTotal = myGrandTotal + Convert.ToDouble(mySubTotal);
myOrderNo = (String)dataRow["OrderNo"];
mySubTotal = 0;
myTotalPrice = 0;
}
else
{
myTotalPrice = myTotalPrice +
Convert.ToDouble(dataRow["TotalPrice"]) ;
}

}

dr2 = myTable.NewRow();
dr2["CustNo"] = "Grand Total : ";
dr2["TotalPrice"] = myGrandTotal;

myTable.Rows.Add(dr2);
myTable.AcceptChanges();

DetailGrid.DataSource = myTable;

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Tai Kelvin <ke*******@gmail.com> wrote:
I don't why I can't insert new rows between rows, and it can append on
buttom record of datatable. With reference my code, Using Rows.InserAt
or Rows.Add() is the better. Please advise.


As I said before, please provide a short but *complete* program which
demonstrates the problem.

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
1
by: Derrick | last post by:
Hi all, I've been trying to understand exactly how to insert a newly created DataRow into a DataRowCollection at a specified row value without much luck. At first I was just appending the...
0
by: Dave Elliott | last post by:
After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the...
5
by: Dave | last post by:
I tried posting this in the WinForm forum and got no hits so I am trying it here. After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
0
by: Kelvin | last post by:
Hi All, I don't why I can't insert new rows between rows, and it can append on buttom record of datatable. With reference my code, Using Rows.InserAt or Rows.Add() is the better. Please advise....
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
1
by: dx | last post by:
Any ideas? I can't find any examples that support this. I'm thinking a solution may be something like inherting arraylist and containing a hashtable. or Inheriting NameObjectCollectionBase...
0
by: inpuarg | last post by:
I have 2 column : Column1 Column2 A 25 B 20 C 15 D 10 E 5 After i load form, i move current cell to D and my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...
0
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...
0
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,...
0
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...

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.