Copying or Converting datacolumn into array
-
Can anybody tell me how can I copy a whole data column from a data table into an array of integers ? OR how can I read values of all the rows of a datacolumn (using for loop) and then pass these values to an array (double [] data).
-
Can anybody tell me how can I copy a whole data column from a data table into an array of integers ? OR how can I read values of all the rows of a datacolumn (using for loop) and then pass these values to an array (double [] data).
System.Collections.Generic.List<int> intValues = new List<int>(); foreach (DataRow r in dt.Rows) { //FIx to hand nulls if necessary intValues.Add((int)r["myColumnName"]); } return (int[])intValues.ToArray();
I didn't get any requirements for the signature
-
System.Collections.Generic.List<int> intValues = new List<int>(); foreach (DataRow r in dt.Rows) { //FIx to hand nulls if necessary intValues.Add((int)r["myColumnName"]); } return (int[])intValues.ToArray();
I didn't get any requirements for the signature
Thanks for taking interest in my problem. My solution file successfully builds up at compile time but at run time , I am getting following error. Please help. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Line 93: { Line 94: //FIx to hand nulls if necessary Line 95: data.Add((double)r["A"]); Line 96: } Line 97: // return (double[])intValues.ToArray(); Source File: C:\Users\Ashutosh\Documents\Visual Studio 2008\Projects\testing_buttonClickEvent\testing_buttonClickEvent\Default.aspx.cs Line: 95 Stack Trace: [InvalidCastException: Specified cast is not valid.] testing_buttonClickEvent._Default.Button1_Click(Object sender, EventArgs e) in C:\Users\Ashutosh\Documents\Visual Studio 2008\Projects\testing_buttonClickEvent\testing_buttonClickEvent\Default.aspx.cs:95 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +107 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3436
-
Thanks for taking interest in my problem. My solution file successfully builds up at compile time but at run time , I am getting following error. Please help. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Line 93: { Line 94: //FIx to hand nulls if necessary Line 95: data.Add((double)r["A"]); Line 96: } Line 97: // return (double[])intValues.ToArray(); Source File: C:\Users\Ashutosh\Documents\Visual Studio 2008\Projects\testing_buttonClickEvent\testing_buttonClickEvent\Default.aspx.cs Line: 95 Stack Trace: [InvalidCastException: Specified cast is not valid.] testing_buttonClickEvent._Default.Button1_Click(Object sender, EventArgs e) in C:\Users\Ashutosh\Documents\Visual Studio 2008\Projects\testing_buttonClickEvent\testing_buttonClickEvent\Default.aspx.cs:95 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +107 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3436
put a break point on there and check to see what type r["A"] is. perhaps it is dbnull or some other value that is not a double. should be an easy fix.
I didn't get any requirements for the signature