Hi all expert,
I have two fields in data grid one comboxbox type another is texbox type. As per user selection I want to add multiple record at a time in backend. Here is my looping code…pls somebody help………help…help………me..inside looping code I am getting casting exceptions.
Unable to cast object of type 'System.String' to type 'Create_Sales_Back_Order.DynamicsGPService.SalesBackorderLine[]'.
for (int counter = 0; counter < (CreateSalesBackOrderGrid.Rows.Count); counter++)
{
salesBackorder.Lines = (SalesBackorderLine[])CreateSalesBackOrderGrid.Rows[counter].Cells[0].Value; //here getting this exception.
//here I should write insert method.
}
Sam HobbsPosted Sep 27, 2010, 6:28 PM
India ProgrammerPosted Sep 27, 2010, 8:42 AM
1)First of all though I am entering 3 records…its showing row count as 4.
2) SalesBackorderLine[] lines = new SalesBackorderLine[CreateSalesBackOrderGrid.Rows.Count];
In this lines =null showing..
and new SalesBackorderLine[CreateSalesBackOrderGrid.Rows.Count]=4 showing.
3) Lines(CreateSalesBackOrderGrid.Rows.Count) = salesBackorderLine ..here value showing as 4
Manikavelu VelayuthamPosted Sep 27, 2010, 8:27 AM
CreateSalesBackOrderGrid.Rows.Count and lines
If both are same then ther wont be a chance of index out of range error.
if both are not same surely it will throw the error
put a break point and debug each loop, there you can easily fix the bug
let me know once your resolved this issue
India ProgrammerPosted Sep 27, 2010, 8:22 AM
Still getting the same exception "Index was outside the bounds of the array"
Manikavelu VelayuthamPosted Sep 27, 2010, 8:16 AM
for (int counter = 0; counter < CreateSalesBackOrderGrid.Rows.Count; counter++)
with this code
for (int counter = 0; counter < CreateSalesBackOrderGrid.Rows.Count-1; counter++)
India ProgrammerPosted Sep 27, 2010, 8:14 AM
Hi,
Now I have changed the code: getting exception.. Index out of range.
SalesBackorderLine[] lines = new SalesBackorderLine[CreateSalesBackOrderGrid.Rows.Count];
for (int counter = 0; counter < CreateSalesBackOrderGrid.Rows.Count; counter++)
{
salesBackorderLine = new SalesBackorderLine();
salesBackorderLine.ItemKey = itemKey;
salesBackorderLine.Quantity = backorderCount;
lines[CreateSalesBackOrderGrid.Rows.Count]=salesBackorderLine; //in this line getting exception Index out of range.
}
Manikavelu VelayuthamPosted Sep 27, 2010, 5:06 AM
May i know what type is it