|
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 | |
Share:
|
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 discussion thread is closed Replies have been disabled for this discussion. Similar topics
6 posts
views
Thread by Dan V. |
last post: by
|
2 posts
views
Thread by kids_pro |
last post: by
|
1 post
views
Thread by George |
last post: by
|
7 posts
views
Thread by Peter Afonin |
last post: by
|
3 posts
views
Thread by RBCC |
last post: by
|
16 posts
views
Thread by stojilcoviz |
last post: by
|
3 posts
views
Thread by David |
last post: by
|
4 posts
views
Thread by =?Utf-8?B?YmFzdWxhc3o=?= |
last post: by
|
4 posts
views
Thread by StinkyDuck |
last post: by
| | | | | | | | | | |