Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Copying or Converting datacolumn into array

Copying or Converting datacolumn into array

Scheduled Pinned Locked Moved ASP.NET
questiondata-structures
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ashutosh_karna
    wrote on last edited by
    #1

    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).

    T 1 Reply Last reply
    0
    • A ashutosh_karna

      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).

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • T ToddHileHoffer

        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

        A Offline
        A Offline
        ashutosh_karna
        wrote on last edited by
        #3

        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

        T 1 Reply Last reply
        0
        • A ashutosh_karna

          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

          T Offline
          T Offline
          ToddHileHoffer
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups