Hi,
I have a code that creates a datatable from an arraylist, but i am getting
an error in casting in
for (int intRow = 0; intRow < alLCPlist.Count; intRow++)
{
DataRow drow = dtLCPack.NewRow();
int intColCount = dtLCPack.Columns.Count;
ArrayList arrlRow = (ArrayList)alLCPlist[intRow]; <== Specified cast
is not valid here
for (int intCol=0; intCol < intColCount; intCol++)
{
drow[intCol] = arrlRow[intCol];
}
dtLCPack.Rows.Add(drow);
}
Can someone help me how to fix it?
Thanks
Gane 6 5361
Without seeing what alLCPlist is and how it's populated, it's quite hard to
help. Clearly,alLCPlist doesn't contain arraylists...
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"gane kol" <ga*****@softca.com> wrote in message
news:O2**************@TK2MSFTNGP12.phx.gbl... Hi,
I have a code that creates a datatable from an arraylist, but i am getting an error in casting in
for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow = dtLCPack.NewRow(); int intColCount = dtLCPack.Columns.Count; ArrayList arrlRow = (ArrayList)alLCPlist[intRow]; <== Specified
cast is not valid here for (int intCol=0; intCol < intColCount; intCol++) { drow[intCol] = arrlRow[intCol]; } dtLCPack.Rows.Add(drow); } Can someone help me how to fix it?
Thanks Gane
Well, the code before the for loop is
--------
ArrayList alLCPlist = new ArrayList();
DataRow dr;
for (int i=0;i<infoNode.ChildNodes.Count;i++)
{
currentNode = infoNode.ChildNodes[i];
alLCPlist = product.GetLCPack(strvalue,
currentNode.Attributes["Name"].Value.ToString());
if (alLCPlist.Count > 0)
{
------
alLCPlist gets the data returned from the dataaccess layer.
product.GetLCPack returns an arraylist.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Or**************@TK2MSFTNGP15.phx.gbl... Without seeing what alLCPlist is and how it's populated, it's quite hard
to help. Clearly,alLCPlist doesn't contain arraylists...
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!) "gane kol" <ga*****@softca.com> wrote in message news:O2**************@TK2MSFTNGP12.phx.gbl... Hi,
I have a code that creates a datatable from an arraylist, but i am
getting an error in casting in
for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow = dtLCPack.NewRow(); int intColCount = dtLCPack.Columns.Count; ArrayList arrlRow = (ArrayList)alLCPlist[intRow]; <== Specified cast is not valid here for (int intCol=0; intCol < intColCount; intCol++) { drow[intCol] = arrlRow[intCol]; } dtLCPack.Rows.Add(drow); } Can someone help me how to fix it?
Thanks Gane
alLCPList itself is an arraylist, because, as you say, GetLCPack returns an
arraylist...but what does the items within the array list contain?
ArrayList arr = new ArrayList()
arr.Add("1");
arr.Add("2");
arr.Add("3");
string value = (string)arr[1];
ArrayList arr = new ArrayList()
arr.Add(1);
arr.Add(2);
arr.Add(3);
int value = (int)arr[0];
ArrayList arr = new ArrayList()
arr.Add(new DataSet());
arr.Add(new DataSet());
arr.Add(new DataSet());
DataSet value = (DataSet)arr[2];
if you are casting an item of the arraylist to arraylist, than this item
must be an arraylist, ala:
ArrayList arr = new ArrayList()
arr.Add(new ArraList());
arr.Add(new ArraList());
arr.Add(new ArraList());
ArraListvalue = (ArraList)arr[1];
If you are getting an invalid cast, then the items within your alLCPlist
ArrayList aren't embedded ArrayLists..
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"gane kol" <ga*****@softca.com> wrote in message
news:uI**************@TK2MSFTNGP10.phx.gbl... Well, the code before the for loop is -------- ArrayList alLCPlist = new ArrayList();
DataRow dr;
for (int i=0;i<infoNode.ChildNodes.Count;i++)
{
currentNode = infoNode.ChildNodes[i];
alLCPlist = product.GetLCPack(strvalue, currentNode.Attributes["Name"].Value.ToString());
if (alLCPlist.Count > 0)
{
------
alLCPlist gets the data returned from the dataaccess layer. product.GetLCPack returns an arraylist. "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:Or**************@TK2MSFTNGP15.phx.gbl... Without seeing what alLCPlist is and how it's populated, it's quite hard to help. Clearly,alLCPlist doesn't contain arraylists...
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!) "gane kol" <ga*****@softca.com> wrote in message news:O2**************@TK2MSFTNGP12.phx.gbl... Hi,
I have a code that creates a datatable from an arraylist, but i am getting an error in casting in
for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow = dtLCPack.NewRow(); int intColCount = dtLCPack.Columns.Count; ArrayList arrlRow = (ArrayList)alLCPlist[intRow]; <== Specified cast is not valid here for (int intCol=0; intCol < intColCount; intCol++) { drow[intCol] = arrlRow[intCol]; } dtLCPack.Rows.Add(drow); } Can someone help me how to fix it?
Thanks Gane
Actually i am converting a datareader to arraylist.
----------
arrOracleParams[0] = objDB.BuildOracleParameter("Product",
System.Data.OracleClient.OracleType.VarChar,
ParameterDirection.Input,Product,50);
arrOracleParams[1] = objDB.BuildOracleParameter("Type",
System.Data.OracleClient.OracleType.VarChar,
ParameterDirection.Input,Type,20);
arrOracleParams[2] = objDB.BuildOracleParameter("pCursor",
System.Data.OracleClient.OracleType.Cursor,
ParameterDirection.Output,null,0);
OracleDataReader objOraReader =
objDB.RunExecuteOracleDataReader("pkg_Prod.sp_get_ CP", arrOracleParams);
while (objOraReader.Read())
{
object[] values = new object[objOraReader.FieldCount];
objOraReader.GetValues(values);
alList.Add(values);
}
return alList;
------
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:eq**************@TK2MSFTNGP10.phx.gbl... alLCPList itself is an arraylist, because, as you say, GetLCPack returns
an arraylist...but what does the items within the array list contain?
ArrayList arr = new ArrayList() arr.Add("1"); arr.Add("2"); arr.Add("3"); string value = (string)arr[1];
ArrayList arr = new ArrayList() arr.Add(1); arr.Add(2); arr.Add(3); int value = (int)arr[0];
ArrayList arr = new ArrayList() arr.Add(new DataSet()); arr.Add(new DataSet()); arr.Add(new DataSet()); DataSet value = (DataSet)arr[2];
if you are casting an item of the arraylist to arraylist, than this item must be an arraylist, ala:
ArrayList arr = new ArrayList() arr.Add(new ArraList()); arr.Add(new ArraList()); arr.Add(new ArraList()); ArraListvalue = (ArraList)arr[1];
If you are getting an invalid cast, then the items within your alLCPlist ArrayList aren't embedded ArrayLists..
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!) "gane kol" <ga*****@softca.com> wrote in message news:uI**************@TK2MSFTNGP10.phx.gbl... Well, the code before the for loop is -------- ArrayList alLCPlist = new ArrayList();
DataRow dr;
for (int i=0;i<infoNode.ChildNodes.Count;i++)
{
currentNode = infoNode.ChildNodes[i];
alLCPlist = product.GetLCPack(strvalue, currentNode.Attributes["Name"].Value.ToString());
if (alLCPlist.Count > 0)
{
------
alLCPlist gets the data returned from the dataaccess layer. product.GetLCPack returns an arraylist. "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:Or**************@TK2MSFTNGP15.phx.gbl... Without seeing what alLCPlist is and how it's populated, it's quite
hard to help. Clearly,alLCPlist doesn't contain arraylists...
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!) "gane kol" <ga*****@softca.com> wrote in message news:O2**************@TK2MSFTNGP12.phx.gbl... > Hi, > > I have a code that creates a datatable from an arraylist, but i am getting > an error in casting in > > for (int intRow = 0; intRow < alLCPlist.Count; intRow++) > { > DataRow drow = dtLCPack.NewRow(); > int intColCount = dtLCPack.Columns.Count; > ArrayList arrlRow = (ArrayList)alLCPlist[intRow]; <==
Specified cast > is not valid here > for (int intCol=0; intCol < intColCount; intCol++) > { > drow[intCol] = arrlRow[intCol]; > } > dtLCPack.Rows.Add(drow); > } > Can someone help me how to fix it? > > Thanks > Gane > >
Looks like you are converting it to an array of objects...which is very
different than an array list.
try
object[] arrlRow = (object[])alLCPlist[intRow];
in the initial code you sent ...
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"gane kol" <ga*****@softca.com> wrote in message
news:OJ**************@TK2MSFTNGP14.phx.gbl... Actually i am converting a datareader to arraylist.
---------- arrOracleParams[0] = objDB.BuildOracleParameter("Product", System.Data.OracleClient.OracleType.VarChar, ParameterDirection.Input,Product,50); arrOracleParams[1] = objDB.BuildOracleParameter("Type", System.Data.OracleClient.OracleType.VarChar, ParameterDirection.Input,Type,20); arrOracleParams[2] = objDB.BuildOracleParameter("pCursor", System.Data.OracleClient.OracleType.Cursor, ParameterDirection.Output,null,0); OracleDataReader objOraReader = objDB.RunExecuteOracleDataReader("pkg_Prod.sp_get_ CP", arrOracleParams);
while (objOraReader.Read()) {
object[] values = new object[objOraReader.FieldCount];
objOraReader.GetValues(values);
alList.Add(values);
}
return alList;
------
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:eq**************@TK2MSFTNGP10.phx.gbl... alLCPList itself is an arraylist, because, as you say, GetLCPack returns an arraylist...but what does the items within the array list contain?
ArrayList arr = new ArrayList() arr.Add("1"); arr.Add("2"); arr.Add("3"); string value = (string)arr[1];
ArrayList arr = new ArrayList() arr.Add(1); arr.Add(2); arr.Add(3); int value = (int)arr[0];
ArrayList arr = new ArrayList() arr.Add(new DataSet()); arr.Add(new DataSet()); arr.Add(new DataSet()); DataSet value = (DataSet)arr[2];
if you are casting an item of the arraylist to arraylist, than this item must be an arraylist, ala:
ArrayList arr = new ArrayList() arr.Add(new ArraList()); arr.Add(new ArraList()); arr.Add(new ArraList()); ArraListvalue = (ArraList)arr[1];
If you are getting an invalid cast, then the items within your alLCPlist ArrayList aren't embedded ArrayLists..
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!) "gane kol" <ga*****@softca.com> wrote in message news:uI**************@TK2MSFTNGP10.phx.gbl... Well, the code before the for loop is -------- ArrayList alLCPlist = new ArrayList();
DataRow dr;
for (int i=0;i<infoNode.ChildNodes.Count;i++)
{
currentNode = infoNode.ChildNodes[i];
alLCPlist = product.GetLCPack(strvalue, currentNode.Attributes["Name"].Value.ToString());
if (alLCPlist.Count > 0)
{
------
alLCPlist gets the data returned from the dataaccess layer. product.GetLCPack returns an arraylist. "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:Or**************@TK2MSFTNGP15.phx.gbl... > Without seeing what alLCPlist is and how it's populated, it's quite hard to > help. Clearly,alLCPlist doesn't contain arraylists... > > Karl > > -- > MY ASP.Net tutorials > http://www.openmymind.net/ - New and Improved (yes, the popup is > annoying) > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more
to > come!) > "gane kol" <ga*****@softca.com> wrote in message > news:O2**************@TK2MSFTNGP12.phx.gbl... > > Hi, > > > > I have a code that creates a datatable from an arraylist, but i am getting > > an error in casting in > > > > for (int intRow = 0; intRow < alLCPlist.Count; intRow++) > > { > > DataRow drow = dtLCPack.NewRow(); > > int intColCount = dtLCPack.Columns.Count; > > ArrayList arrlRow = (ArrayList)alLCPlist[intRow]; <== Specified > cast > > is not valid here > > for (int intCol=0; intCol < intColCount; intCol++) > > { > > drow[intCol] = arrlRow[intCol]; > > } > > dtLCPack.Rows.Add(drow); > > } > > Can someone help me how to fix it? > > > > Thanks > > Gane > > > > > >
That works great,
I appreciate that Karl,
Thanks.
Gane
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Looks like you are converting it to an array of objects...which is very different than an array list.
try
object[] arrlRow = (object[])alLCPlist[intRow];
in the initial code you sent ...
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!) "gane kol" <ga*****@softca.com> wrote in message news:OJ**************@TK2MSFTNGP14.phx.gbl... Actually i am converting a datareader to arraylist.
---------- arrOracleParams[0] = objDB.BuildOracleParameter("Product", System.Data.OracleClient.OracleType.VarChar, ParameterDirection.Input,Product,50); arrOracleParams[1] = objDB.BuildOracleParameter("Type", System.Data.OracleClient.OracleType.VarChar, ParameterDirection.Input,Type,20); arrOracleParams[2] = objDB.BuildOracleParameter("pCursor", System.Data.OracleClient.OracleType.Cursor, ParameterDirection.Output,null,0); OracleDataReader objOraReader = objDB.RunExecuteOracleDataReader("pkg_Prod.sp_get_ CP", arrOracleParams);
while (objOraReader.Read()) {
object[] values = new object[objOraReader.FieldCount];
objOraReader.GetValues(values);
alList.Add(values);
}
return alList;
------
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:eq**************@TK2MSFTNGP10.phx.gbl... alLCPList itself is an arraylist, because, as you say, GetLCPack
returns an arraylist...but what does the items within the array list contain?
ArrayList arr = new ArrayList() arr.Add("1"); arr.Add("2"); arr.Add("3"); string value = (string)arr[1];
ArrayList arr = new ArrayList() arr.Add(1); arr.Add(2); arr.Add(3); int value = (int)arr[0];
ArrayList arr = new ArrayList() arr.Add(new DataSet()); arr.Add(new DataSet()); arr.Add(new DataSet()); DataSet value = (DataSet)arr[2];
if you are casting an item of the arraylist to arraylist, than this
item must be an arraylist, ala:
ArrayList arr = new ArrayList() arr.Add(new ArraList()); arr.Add(new ArraList()); arr.Add(new ArraList()); ArraListvalue = (ArraList)arr[1];
If you are getting an invalid cast, then the items within your
alLCPlist ArrayList aren't embedded ArrayLists..
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!) "gane kol" <ga*****@softca.com> wrote in message news:uI**************@TK2MSFTNGP10.phx.gbl... > Well, the code before the for loop is > -------- > ArrayList alLCPlist = new ArrayList(); > > DataRow dr; > > for (int i=0;i<infoNode.ChildNodes.Count;i++) > > { > > currentNode = infoNode.ChildNodes[i]; > > alLCPlist = product.GetLCPack(strvalue, > currentNode.Attributes["Name"].Value.ToString()); > > if (alLCPlist.Count > 0) > > { > > ------ > > alLCPlist gets the data returned from the dataaccess layer. > product.GetLCPack returns an arraylist. > > > > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> > wrote in message news:Or**************@TK2MSFTNGP15.phx.gbl... > > Without seeing what alLCPlist is and how it's populated, it's
quite hard > to > > help. Clearly,alLCPlist doesn't contain arraylists... > > > > Karl > > > > -- > > MY ASP.Net tutorials > > http://www.openmymind.net/ - New and Improved (yes, the popup is > > annoying) > > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ
(more to > > come!) > > "gane kol" <ga*****@softca.com> wrote in message > > news:O2**************@TK2MSFTNGP12.phx.gbl... > > > Hi, > > > > > > I have a code that creates a datatable from an arraylist, but i
am > getting > > > an error in casting in > > > > > > for (int intRow = 0; intRow < alLCPlist.Count; intRow++) > > > { > > > DataRow drow = dtLCPack.NewRow(); > > > int intColCount = dtLCPack.Columns.Count; > > > ArrayList arrlRow = (ArrayList)alLCPlist[intRow]; <== Specified > > cast > > > is not valid here > > > for (int intCol=0; intCol < intColCount; intCol++) > > > { > > > drow[intCol] = arrlRow[intCol]; > > > } > > > dtLCPack.Rows.Add(drow); > > > } > > > Can someone help me how to fix it? > > > > > > Thanks > > > Gane > > > > > > > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dan V. |
last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to
pass in a table or query as a parameter and have both columns transform into
a 2D ArrayList. When I sort the one...
|
by: kids_pro |
last post by:
I created a simple Person class as following:
class Person{
private string fname;
private string lname;
public Person(string fname, string lname){
this.fname = fname;
this.lname = lname;
}
|
by: George |
last post by:
I am wondering what is the cost of using DataTable.
Lets say i have 1000 Employee records. The object oriented purist will require the Data Layer to return an ArrayList with 1000 Employee objects....
|
by: Peter Afonin |
last post by:
Hello,
I have a code that queries Active Directory and put logins and names into
the ArrayList. Then I need to bind this ArrayList to the DropdDownList,
making names as DataTextField and logins...
|
by: RBCC |
last post by:
I have a form with a listbox and two textboxes. In the listbox I have the make and models of automobiles. and as the user clicks on the make of the car in the listbox I would like to output the make...
|
by: stojilcoviz |
last post by:
I've a datagrid whose datasource is an arraylist object. The arraylist
holds many instances of a specific class.
I've two questions about this:
1 - Is there a way by which I can obtain a...
|
by: David |
last post by:
Hi all,
I am following this code...
http://www.devarticles.com/c/a/C-Sharp/Interface-IEnumerable-and-IEnumerator-in-C-sharp/2/
I have come to the part with public Customers(). I am assuming...
|
by: =?Utf-8?B?YmFzdWxhc3o=?= |
last post by:
Hi;
I want to store a datatable (or an arraylist) as a session variable but when
I try;
Session = al_RecNo;
I get an error that;
"Cannot implicitly convert type...
|
by: StinkyDuck |
last post by:
I'm trying to determine which type of collection to use, DataTable or
ArrayList. I understand that an ArrayList can be linked to databound
objects if it contains the IList interface.
Is there a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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: 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...
|
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...
| |