(Guid)productFamily1[1] => return value {9dd28cc2-3243-e011-b0cc-005056875e43}
But i getting this error: total.productfamily 'total.productfamily' threw an exception of type 'System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
When i try to assign (Guid)productFamily1[1] into total.ProductFamily as below:-
What is the type of productFamily1[1]? You can't just cast a string to a Guid, you create a new Guid using the string as a parameter to the constructor. So, if productFamily1 is of type string[] then you would need
total.productfamily = new Guid(productFamily1[1]);
foreach (DataRow
aPFRow in distinctAProductFamily.Rows)
{
if ((string)aPFRow["productfamilyname"]
== name)
{
aPro=(Guid)aPFRow["productfamily"];
}
}
return (aPro);
}
total.productfamily = productFamily1[1];
I used watch to trace the value for productFamily1[1] return value {...........} as above mentiod. It's Guid.
But i try to assigned into total.productfamily, where the watch return above mentioned error. I get stuck. Logicall it's should work. But technically i am failed. :-(
Please help. Appreciate for your kind respond & help.
I can't see a problem, immediately. Can you put a breakpoint on the line
total.productfamily = productFamily1[1];
check that productFamily1[1] is correct at this point and then step once and see what the value of total.productFamily is? If you now continue is this line executed again? What line actually generates the exception?
The StrongTypingException is generated when you try to store a null in a dataset field that does not allow nulls.
By the way. In c# array indexes start at 0. When you declare an array to be new fred[10] then the elements are indexed from 0 to 9. So it would be more natural to set k = 0 and to use element zero of the array.
The logic around filterbyproductfamily doesn't look right either. It seems that it only reflects the validity of the last checked item as it is overwritten each time around the loop.
How can i make the bold section accept multi scalar parameter matching likes [Contains] or [ where fieldname
IN('Parameter1','Parameter2','Parameter3...) ]?
I have a dropdownbox with mutiselect. I want the dataset row total to sum up the productfamily that i have selected with others criteria expression. Now, i only successful to get 1 item selected total no matter how many item been selected. The problem is
causing by Guid[].
micnie2020
Member
308 Points
537 Posts
System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
Apr 16, 2012 02:12 AM|LINK
Dear All,
(Guid)productFamily1[1] => return value {9dd28cc2-3243-e011-b0cc-005056875e43}
But i getting this error:
total.productfamily 'total.productfamily' threw an exception of type 'System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
When i try to assign (Guid)productFamily1[1] into total.ProductFamily as below:-
total.productfamily = (Guid)productFamily1[1];
Can anyone help me on this?
Thank you.
Regards,
Micheale
Paul Linton
Star
13571 Points
2571 Posts
Re: System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
Apr 16, 2012 03:53 AM|LINK
What is the type of productFamily1[1]? You can't just cast a string to a Guid, you create a new Guid using the string as a parameter to the constructor. So, if productFamily1 is of type string[] then you would need
total.productfamily = new Guid(productFamily1[1]);
micnie2020
Member
308 Points
537 Posts
Re: System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
Apr 16, 2012 04:03 AM|LINK
Hi Paul,
It's Guid.
Here the process flow:-
-------------------------- Bold section will call the function, and return Guid value --------------
int k = 1;
Guid[] productFamily1 = new Guid[10];
foreach (ToolStripMenuItem item in tsddbSegment.DropDown.Items) {
if (item.Checked)
{
productFamily1[k] = Helpers.getProduct(item.Text);
filterByProductFamily = (productFamily1[k] !=null && productFamily1[k] != Guid.Empty) ? true : false;
k = k + 1;
}
}
-------------------------------------- Function to retrieve Guid ----------------------------
public static Guid getProduct(string name) {
frmMain mainForm = (frmMain)Application.OpenForms["frmMain"];
DataSet1 dataset = mainForm.GetDataSet();
// Get distinct set of Families referenced in opportunity dataset
DataView tempView = new DataView(dataset.OpportunityElement, null, "productfamilyname", DataViewRowState.CurrentRows);
DataTable distinctAProductFamily = tempView.ToTable(true, new string[] { "productfamilyname", "productfamily" });
Guid aPro = Guid.Empty;
// Create list of region options
foreach (DataRow aPFRow in distinctAProductFamily.Rows)
{
if ((string)aPFRow["productfamilyname"] == name)
{
aPro=(Guid)aPFRow["productfamily"];
}
}
return (aPro);
}
total.productfamily = productFamily1[1];
I used watch to trace the value for productFamily1[1] return value {...........} as above mentiod. It's Guid.
But i try to assigned into total.productfamily, where the watch return above mentioned error. I get stuck. Logicall it's should work. But technically i am failed. :-(
Please help. Appreciate for your kind respond & help.
Thank you.
Regards,
Micheale
Paul Linton
Star
13571 Points
2571 Posts
Re: System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
Apr 16, 2012 04:46 AM|LINK
I can't see a problem, immediately. Can you put a breakpoint on the line
total.productfamily = productFamily1[1];
check that productFamily1[1] is correct at this point and then step once and see what the value of total.productFamily is? If you now continue is this line executed again? What line actually generates the exception?
The StrongTypingException is generated when you try to store a null in a dataset field that does not allow nulls.
By the way. In c# array indexes start at 0. When you declare an array to be new fred[10] then the elements are indexed from 0 to 9. So it would be more natural to set k = 0 and to use element zero of the array.
The logic around filterbyproductfamily doesn't look right either. It seems that it only reflects the validity of the last checked item as it is overwritten each time around the loop.
micnie2020
Member
308 Points
537 Posts
Re: System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
Apr 16, 2012 07:16 AM|LINK
Thanks Paul.
I will try to redo the code line by line breakpoint as you have suggested above. Maybe somewhere is wrong.
Thank you.
Regards,
Micheale
Paul Linton
Star
13571 Points
2571 Posts
Re: System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
Apr 16, 2012 07:20 AM|LINK
Guid[] productFamily = new Guid[10];
micnie2020
Member
308 Points
537 Posts
Re: System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
Apr 16, 2012 07:35 AM|LINK
Thank you once again.
micnie2020
Member
308 Points
537 Posts
Re: System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
Apr 16, 2012 08:06 AM|LINK
Hi,
How can i make the bold section accept multi scalar parameter matching likes [Contains] or [ where fieldname IN('Parameter1','Parameter2','Parameter3...) ]?
eg: productFamily[2]
productFamily[0] = Guid {xxxxxxxxxxxxxxxxxxxxxxxxx}
productFamily[1] = Guid {yyyyyyyyyyyyyyyyyyyyyyyy}
Please advise.
Thank you.
for (int i = 1; i <= 10; i++)
{
// Revenues by month
DataSet1.TotalRevenueByMonthRow total = dataSet1.TotalRevenueByMonth.NewTotalRevenueByMonthRow();
total.totalcategory = i;
total.financialyear = year;
total.financialmonth = month;
for(int jj=0; jj<k; jj++)
{
total.productfamily = productFamily[jj];
}
dataSet1.TotalRevenueByMonth.AddTotalRevenueByMonthRow(total);
}
Paul Linton
Star
13571 Points
2571 Posts
Re: System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
Apr 16, 2012 08:41 AM|LINK
Can you give some more explanation about what you want to achieve?
micnie2020
Member
308 Points
537 Posts
Re: System.Data.StrongTypingException' System.Guid {System.Data.StrongTypingException}
Apr 16, 2012 08:49 AM|LINK
Hi Paul,
My objective :
I have a dropdownbox with mutiselect. I want the dataset row total to sum up the productfamily that i have selected with others criteria expression. Now, i only successful to get 1 item selected total no matter how many item been selected. The problem is causing by Guid[].
Thank you.
Regards,
Micheale