DataTable - Read Rows Dynamically

Hi ,
Does anyone knows how to read rows from Datatable dynamically ?
What I'm looking for is: a private function which a collection column names and datatable with rows and that function will return me back  the values of those functions with column names
Bhupinder Singh

Try something like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ConsoleApplication1
class Program
static void Main(string[] args)
DataTable table = new DataTable();
table.Columns.Add("a", typeof(int));
table.Columns.Add("b", typeof(int));
table.Columns.Add("c", typeof(int));
table.Rows.Add(new object[] { 1, 2, 3 });
table.Rows.Add(new object[] { 4, 5, 6 });
table.Rows.Add(new object[] { 7, 8, 9 });
int numCols = table.Columns.Count;
List<string> colNames = new List<string>();
foreach (DataColumn col in table.Columns)
colNames.Add(col.ColumnName);
foreach (DataRow row in table.AsEnumerable())
foreach (string colName in colNames)
int cell = row.Field<int>(colName);
jdweng

Similar Messages

  • Emailing datatable with rows determined by sessionbean properties

    Is it possible to email a datable (a link for the datatable) with rows determined by sessionbean parameters? Even after the session expires the link should work. (That means the session properties should be embeded in the link)
    Thank you very much.

    I want to email search results from a database. The search is carried out by supplying some session properties. The search results are displayed in a datatable.
    The contents of the email can be the datatable itself or a link to the datatable.
    It should be assumed when the recipient see the email the session(used to do the search and send the email) will have expired. Bu till the recipient should be able to load the datatable by clicking the link.

  • Javascript error while creating rows dynamically (IE)

    hi all,
    as per the requirement i am creating rows dynamically by createElement() method ...
    when i load the page method where i am creating the rows is called on onLoad ... bring the data required .. some method code like this ...
    function createRows()
    var myTable = document.getElementById("itemTable");
              var tBody = myTable.getElementsByTagName('tbody')[0];
              alert(tBody);
              var td;
              var classVar;
              var browser = navigator.appName;
              if(browser=="Microsoft Internet Explorer")
                   classVar = "className";
              }else{
                   classVar = "class";
              <%
              Set keyset = checklistItems.keySet();
              Iterator keySetIterator = keyset.iterator();
              while(keySetIterator.hasNext())
                   String checklistType = (String)keySetIterator.next();
                   %>
                   if ((type == "Show_All") || (type == '<%=checklistType%>'))
                                  var newTypeTR = document.createElement('tr');
                                  var newTypeTD = document.createElement('td');
                                  newTypeTD.setAttribute("width","100%");
                                  newTypeTD.setAttribute(classVar,"font_black_s_bold");
                                  if(browser=="Microsoft Internet Explorer")
                                       newTypeTD.innerText = '<%= checklistType %>';
                                  else
                                       newTypeTD.innerHTML = '<%= checklistType %>';
                                  newTypeTR.appendChild (newTypeTD);
                                  newTypeTR.setAttribute(classVar,"td5");
                                  tBody.appendChild (newTypeTR);
    table is defined in jsp like
    <table width="727" cellSpacing="0">
                   <tr>
                        <td>
                             <div id="checklist_item_div">
                                  <table border="0" id='itemTable' width="100%" cellPadding="4" cellSpacing="0">     
                                  <tbody>
                                       <tr>
                                       </tr>     
                                  </tbody>
                                  </table>
                             </div>
                        </td>
                   </tr>
    </table>
    Now i have a combo box on my page , where onchange i am bringing new data using ajax to fill ....
    and now i want to flush all the rows i created earlier ...and again call the same method as above to create the rors and cols dynamically ...
    so after ajax call my script code to flush all rows and cols like
    var browser=navigator.appName;
                        if(browser=="Microsoft Internet Explorer")
                             itmTable.innerText = "<tbody></tbody>";
                        else
                             itmTable.innerHTML = "<tbody> </tbody>";
    but when i call the createRows function after this , i got the error on the line
    tBody.appendChild (newTypeTR);
    as tBody now getting as undefined .... this problem is with IE (working on IE 7.0)
    works very fine on firefox and safari browsers ...
    please helm me out ...
    Edited by: prashant-kadam on Jun 12, 2008 5:22 AM

    what does this have to do with Java?
    hint: Java != Javascript

  • Database "read all data.vi" not able to read row contents

    Good day,
    I'm trying to read a table from an Excel Database, with the NI VI "Read all data.vi" provided as an example VI.  The VI is slighlty modified to have the file dialog box wired to the open connection VI.  This file dialog provides the connection information to the Excel database.   So far only the column names are showing, but not any row content, as you can see in the screenshot - front_panel.
    What the VI does :
    - finds the table name(s)
    - finds the column name(s)
    Problem with the system:
    - can't read row data.
    The Excel file in question is really really simple.
    here is the content of the dsn file:
    [ODBC]
    DRIVER=Microsoft Excel Driver (*.xls)
    UID=admin
    UserCommitSync=Yes
    Threads=3
    SafeTransactions=0
    ReadOnly=0
    PageTimeout=5
    MaxScanRows=8
    MaxBufferSize=2048
    FIL=excel 8.0
    DriverId=790
    DefaultDir=C:\MPBC\My Database
    DBQ=C:\MPBC\My Database\SIMPLEST.xls
    Any hints on how to get row data?
    Thanks in advance.
    ---info---------
    LabVIEW 8.6
    Excel 9.0  or 2000
    Win XP pro SP3
    FB
     

    Well, as I said, I can't help with treating Excel as a DataBase, but here is some code to read your Excel file.  I actually read it twice, the first time returning all of the data in a single array (you can split it yourself into Header and Data), and the second time I read in a single row into Header (the Read returns a 2D array, which I turn into 1D) and a second Read for the rest of the data.  To read the rest, I first figure out the "next" row (one past the last row, so I decrement it to get the last row) and specify all the columns).  The 100 msec time delay between Excel Reads is to give Excel a chance to "cool down" (trust me, without the Delay, Excel will throw an Error).  Note that this is a Snippet -- you can drag it into a LabVIEW 2014 Block Diagram and it will become LabVIEW code.
    Hmm -- I just noticed that you seem to be using LabVIEW 8.6, more than 5 years old.  I don't know if this version of the RGT is available in that older version.
    Bob Schor

  • Add row dynamically in the table.

    Please suggest me javascript function to add row dynamicly in the table whenever i click the add button..........
    thanks...........

    Put a "delete row" button to your repeating subform and use the following script on the click event:<br />form1.page1.<repeating_subform>.instanceManager.removeInstance(this.parent.index);<br /><br />Oguz<br />www.kgc.com.tr

  • DataTable single row coloumn display as two rows..

    I need to display dataTable single Row columns in 2 rows.
    For Eg :
    dataTable each rows has 4 columns...
    by defalut it displays col1 Col2 Col3 Col4.
    But i need to displays
    row1 : Col1 Col2
    Col3 Col4
    row2 : Col1 Col2
    Col3 Col4
    I tried with inner and outer table combination but still having problems.
    Does anyone has any code or sample code for this..
    Thanks in Advance.

    It is hard to follow what you are asking. Do you mean that you want col3 and col4 to show up below col1 and col2 (new row?).
    I am going to assume that you want to "split" or "wrap" your columns. To do this you need to provide the dataTable the proper datamodel.
    <h:dataTable var="foo" model="bar">
    <h:column>
    <h:panelGrid columns="1">
    <h:outputText value="col1">
    <h:outputText value="col3"
    </h:panelGrid>
    </h:column>
    <h:column>
    <h:panelGrid columns="1">
    <h:outputText value="col2">
    <h:outputText value="col4"
    </h:panelGrid>
    </h:column>
    <h:dataTable

  • Dynamic datatable:adding rows

    I am working with Dynamic datatable . whilke adding a row i am able to add only one row . later i am unable to a dd .
    code:
    <h:commandLink value="ADD" action="#{icdMBean.actionAddrow}" />
    back bean:
    public void actionAddrow() {
    // Create new items.
    icdList= new ArrayList<Icd>();
    Icd myNewDataItem = new Icd();System.out.println("i am in action add row2");
    myNewDataItem.setId("new");
    icdList.add(myNewDataItem);
    if i set the id value( myNewDataItem.setId("new");) only i am able to add only one row .
    could you please suggest a solution for it.

    Hi, many thanks for your answer, so what do you think is the best solution for adding rows by user to interactive form's dynamic table?
    Manually read xml data during submit by this way: https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/9121. [original link is broken] [original link is broken] [original link is broken] ?
    Or is there better solution for this? (any link to some examples, blogs, etc...)
    Many thanks for any answer!

  • Read mutliple dynamic rows of a Table in Adobe Form into GP's context

    Hello All,
    I have a GP scenario where in user inputs multiple rows of data in a table which is on an Interactive Adobe Form.
    I want to read those values entered dynamically and passed between callable objects.
    Please could you suggest on this? If you post any sample code that would be of great help.
    Best Regards,
    Suyukti B N

    Hi Tamas,
    I checked the mentioned form and, as this table is setted as TABLEROW and some of its cells are static, is not possible to change the column size in the layout or even though changing it directly in the XML file, cell by cell. I was trying it.
    For example, choose the Cell6 of TABLEROW[0] and click on tab 'XML Source'. You will see this statement:
    <draw colSpan="3" h="16.3166mm" name="Cell7" w="22.225mm">
    You can try to change the value 'colSpan' according to your requirement.
    This table size is not modifiable because it was developed to it.
    I believe that Diego's suggestion can help in this case, if you are having problems to print the entire table on the page.
    Regards,
    Lucas Comassetto.

  • How to make table control rows dynamic/unlimited using TC with Wizard

    Hi Friends ,
    I have designed a table control layout using table control with wizard.
    Now the problem is when we design a TC layout ,then we have to design it on the page . The page has upper & lower limits. so the maximum size & maximum rows in layout is limited. I have tried to create a TC layout with maximum size & maximum rows . Maximum rows created in Layout is 25.
    Now suppose if enduser wants 100 entries to enter by coping a file of 100 records in my TC present on entry screen , then ONLY 25 entries are displayed on entry scren before doing any user action or saving and after saving only these 25 entries are sved in DB. Means enrtries from 26 to 100 are not displayed on entry screen or saved in DB.
    So my requirement is to display all 100 entries at a time in entry screen before saving with scrolling up & down facility and these 100 entries should also get saved in DB after clicking save button. In short I want dynamic entry screen table control which can show/dieplay Any Number . of entries whatever the number may be entered by enduser .
    Plz note that I have used all 3 facilliteis i.e.
    1. Scrolling
    2. INSERT/DELETE
    3. SELECT/DESELECT
    while designing TC with wizard .
    Scrolling buttons like FIRST PAGE, PREV. PAGE, NEXT PAGE, LAST PAGE are displayed.
    BUT they are not functioning though there is system generated code present in both MPP and in PBO & PAI. After clicking any of them , data which is dislaying on entry screen ( Here it is 25 entries ) is getting cleared/disappeared from enry entry screen.
    Waiting for ur response & solutions.
    Thanks & Regards,
    Sudhir

    Hi Ashish ,
    Do one thing .
    At PAI of screen holding TC , there is module name tc_mark on request .
    in this module , there is work area declared g_tc_wa .
    Now go to tc_init module of pbo , where u have given your select command .
    select * from ........................................
    use this code .
    if g_tc_wa is initial .
       SELECT * FROm
       g_tc_wa = 'X'.
       REFRESH CONTROL 'TC' FROM SCREEN dynnr.
       ENDIF.
    Just do this , m sure all buttons, insert, delete , scroll bar.. everything will work .

  • SSIS : Read Rows from an Object variable in SSIS Script Task which is looped many times.

    Hello All,
    Here is what I am trying to do...
    1. I am having two rows, one column in an Object Variable. (vLoopCountObj).
    2. I am having 30 Rows, 2 Columns in my second Object  Variable (vTableRowsObj)
    3. I have a FOR EACH LOOP which will run for number of rows in vLoopCountObj i.e 2 times here.
    4. I have a Script Task inside the FOR EACH LOOP to display all the rows of vTableRowsObj.
    5. When I execute, 30 Rows gets displayed only once. It will not display when the loop goes for second iteration. Please help me to display for second time.
    6. I have used below code to display the rows whithin the script task which is in SSIS dataflow task.
    Imports System
    Imports System.Data
    Imports System.Math
    Imports Microsoft.SqlServer.Dts.Runtime
    Imports System.Xml
    Imports System.Collections
    Imports System.Data.OleDb
    Public Class ScriptMain
    Public Sub Main()
    Dim oleDA As New OleDbDataAdapter
    Dim dt As New DataTable
    Dim col As DataColumn
    Dim row As DataRow
    Dim sMsg As String
    oleDA.Fill(dt, Dts.Variables("vTableRowsObj").Value)
    MsgBox("Number of Rows " + dt.Rows.Count.ToString())
    For Each row In dt.Rows
    For Each col In dt.Columns
    sMsg = sMsg & col.ColumnName & ": " & row(col.Ordinal).ToString & vbCrLf
    Next
    MsgBox(sMsg)
    sMsg = ""
    Next
    Dts.TaskResult = Dts.Results.Success
    End Sub
    End Class

    Hi Raj,
    It is verrrry interesting issue. I can also confirm that it doesnt loop again. I've made a simple test and figured that in the second loop even you fill the Dataadapter, record count is zero. Which brings me up to the idea: Somehow, after you read the object
    variable resultset, you can not read it again in the for each loop.
    Strange, probably a bug or a technical issue that is beyond my existing knowledge.
    I can provide a workaround. You can also loop in script task for first variable. (Nested loops)
    Let other members to examine and comment on this.
    Regards
    Onur
    (For others who also wants to test, here is my scenario
    Execute SQL Task 1:
    Query: SELECT 1 as Cnt UNION ALL SELECT 2 as Cnt
    Resultset: Full Resultset
    ResultSet Tab: Name: 0, Variable Name: User::vLoopCountObj;
    Execute SQL Task 2:
    Query: SELECT 1 as ColA, 2 as ColB UNION ALL SELECT 3 as ColA, 4 as ColB UNION ALL SELECT 5 as ColA, 6 as ColB
    Resultset: Full Resultset
    ResultSet Tab: Name: 0, Variable Name: User::vTableRowsObj;
    For Each Loop Container:
    Collection: Enum: ForEach ADO Enum
    Source Object: User::vLoopCountObj
    Enum Mode: Rows n the first Table
    Script Task:
    ReadOnlyVariables: User::vTableRowsObj
    Script Source:
    Imports System
    Imports System.Data
    Imports System.Math
    Imports Microsoft.SqlServer.Dts.Runtime
    Imports System.Xml
    Imports System.Collections
    Imports System.Data.OleDb
    Public Class ScriptMain
    Public Sub Main()
    Dim oleDA As New OleDbDataAdapter
    Dim dt As New DataTable
    Dim col As DataColumn
    Dim row As DataRow
    Dim sMsg As String
    oleDA.Fill(dt, Dts.Variables("vTableRowsObj").Value)
    Dts.Events.FireInformation(-1, "START!!!!!!!!!!!!!!", "START LOOP", "", 0, True)
    Dts.Events.FireInformation(1, "RowCount: ", dt.Rows.Count.ToString(), "", 0, True)
    For Each row In dt.Rows
    For Each col In dt.Columns
    sMsg = sMsg & col.ColumnName & ": " & row(col.Ordinal).ToString & vbCrLf
    Next
    Dts.Events.FireInformation(1, "Msg: ", sMsg, "", 0, True)
    sMsg = ""
    Next
    Dts.TaskResult = ScriptResults.Success
    End Sub
    End Class
    BI and ERP Senior Consultant @ Nexum Bogazici
    If it is, Please dont forget to mark as answered or at least vote as helpful if the post helps you in any ways.

  • Using Table name in Read statement dynamically

    Hi Experts,
    I have the following requirement.
    Based on a country code say "A" , "B", "C" and based on this i have to read different internal tables lt_tabA, lt_tabB and lt_tabC.
    The table key can be given dynamically, but how can i use the internal table name dynamically without using if statements.
    Please help.
    Thanks!
    Best Regards,
    Gayathri

    Hi Gayathri,
    something like
    DATA:
        lt_t100 TYPE TABLE OF t100,
        lt_t000 TYPE TABLE OF t000.
      FIELD-SYMBOLS:
        <table> TYPE table,
        <rec>   TYPE ANY,
        <field> TYPE ANY.
      SELECT:
        * INTO CORRESPONDING FIELDS OF TABLE lt_t100 FROM t100 UP TO 10 ROWS,
        * INTO CORRESPONDING FIELDS OF TABLE lt_t000 FROM t000 UP TO 10 ROWS.
      CASE abap_true.
        WHEN space.
          ASSIGN  lt_t100 TO <table>.
        WHEN OTHERS.
          ASSIGN  lt_t000 TO <table>.
      ENDCASE.
      READ TABLE <table> with key ('MANDT') = sy-mandt ASSIGNING <rec>.
    Regards,
    Clemens

  • How to create a datatable with row headers and column headers

    Hi,
    I am trying to create a two dimensional datatable which has both column headers and row headers. using <h:datatable> i could create a datatable with only column headers.
    Thanks in advance

    Are you saying that you want a column with only th's? You could also just apply some CSS on that specific column that its rows look like headers.

  • Read a dynamic table in form

    Dear all,
    I have a dynamic table with 3 columns :
    first column which contains a subform with button Add and Remove (to add and remove current row)
    second column with a dropdownlist (first field  to fill in by the user)
    third column with a dropdownlist (second field to fill in by the user).
    I have a check button to check if the user has correctly filled in the table row.
    which script can I write to do that ?
    For example, the user click on add button three times, so I have 3 rows but the user fill in only the first and the second row.
    How to check that the third is empty ?
    Thanks
    Kind regards
    Véronique

    Dear all,
    Structure of my table in the hierachy view :
    myTable
    myRowHeader
    myRowItem      
    ->  myfirstcolumnfield (Button Add - Remove)    ->      mysecondcolumnfield (dropdownlist)
    I found myself the solution :
    To have the number of rows of the dynamic table :
    var w_table_row = xfa.resolveNodes("All_the_hierarchy_object.myTable.myRowItem[*]);
    var w_table_row_lg = w_table_row.length;
    To read the row value :
    var w_row_field1 = xfa.resolveNode("All_the_hierarchy_object.myTable.myRowItem[0].mysecondcolumnfield").rawValue;
    I have to do a loop on index of myRowItem to read each row of myTable
    Hope it is clear and will be helpful.
    Edited by: veronique pinelli on Mar 22, 2010 11:30 AM
    Edited by: veronique pinelli on Mar 22, 2010 11:32 AM

  • How to diplay table row dynamically  by button click

    Hi All,
    I had a table with  with visible row count '3',   i want to display dynamic row  by a button click, mean a 4 th row need to  be added to the table with same like  row '3'.
    please help me ..
    Thanks,
    Raj.

    Hi Raju,
    while click the Add Button,
    Get the all the Rows from the Table  and Put it in to one internal table . after that append the one empty record to that internal table. then again bind to that node.
    Like following code.
      DATA lo_nd_sales TYPE REF TO if_wd_context_node.
      DATA lo_el_sales TYPE REF TO if_wd_context_element.
      DATA ls_sales TYPE wd_this->element_sales.
      DATA lt_sales TYPE wd_this->elements_sales.
    navigate from <CONTEXT> to <SALES> via lead selection
      lo_nd_sales = wd_context->get_child_node( name = wd_this->wdctx_sales ).
    get element via lead selection
      lo_el_sales = lo_nd_sales->get_element(  ).
      CALL METHOD lo_nd_sales->get_static_attributes_table
    EXPORTING
       from   = 1
       to     = 2147483647
        IMPORTING
          table  = lt_sales
      IF lt_sales IS NOT INITIAL.
        CLEAR ls_sales.
        APPEND ls_sales TO lt_sales.
        lo_nd_sales->bind_table( lt_sales ).
      ENDIF.
    Regards,
    Vijay.

  • How to create a table,columns,rows dynamically

    Hi All,
    I would like to build an application which takes from date and to date as inputs and click on button it should create a table dynamically in the following format( rows - project Act1,Service Act2 etc....columns dates and total should be display rowwise and columnwise)
    From 06.22.2009            To 06.23.2009    Go(button)
                          06.22.2009 06.23.2009    Total
    Project act1    2                  2                  4
    Project Act2
    Service Act1    3               3                    6
    Total               5                5
    How do i build this application
    I should have ALV capability so that I can download.
    Thanks
    Bala Duvvuri
    Edited by: Bala Duvvuri on Jun 23, 2009 5:21 AM
    Edited by: Bala Duvvuri on Jun 23, 2009 5:22 AM
    Edited by: Bala Duvvuri on Jun 23, 2009 5:25 AM

    DATA lo_table_settings TYPE REF TO if_salv_wd_table_settings.
      DATA lo_standard_functions TYPE REF TO if_salv_wd_std_functions.
      DATA lo_column_settings TYPE REF TO if_salv_wd_column_settings.
      DATA lo_column TYPE REF TO cl_salv_wd_column.
      DATA lo_column_hdr TYPE REF TO cl_salv_wd_column_header.
      lo_table_settings ?= lo_table.
      lo_table_settings->set_selection_mode( cl_wd_table=>e_selection_mode-auto ).
      lo_table_settings->set_cell_action_event_enabled( value = abap_true ).
      lo_table_settings->set_width( value = '100%' ).
    set default ALV Functions off
      lo_standard_functions ?= lo_table.
    lo_standard_functions->set_sort_headerclick_allowed( abap_false ).
      lo_standard_functions->set_filter_filterline_allowed( abap_false ).
      lo_standard_functions->set_filter_complex_allowed( abap_true ).
      lo_standard_functions->set_sort_complex_allowed( abap_true ).
      lo_standard_functions->set_column_selection_allowed( abap_true ).
      lo_standard_functions->set_view_list_allowed( abap_true ).
      lo_standard_functions->set_pdf_allowed( abap_true ).
      lo_standard_functions->set_export_allowed( abap_true ).
      lo_standard_functions->set_dialog_settings_as_popup( abap_true ).
    lo_standard_functions->set_display_as_allowed( abap_true ).
    lo_standard_functions->set_graphic_allowed( abap_true ).
      lo_column_settings ?= lo_table.
    *To create a row with heading Matter No.
      lo_column = lo_column_settings->get_column( 'MTRID' ).
      lo_column_hdr = lo_column->create_header( ).
      lo_column_hdr->set_text( 'MATTER NO.' ).
    same way for other required field.

Maybe you are looking for

  • Converting Word to PDF-don't link web addresses

    I'm trying to convert a word doc to a pdf using Acrobat XI Standard. The word doc has a hyperlink in one spot and a web address typed out in another spot. The goal I'm looking for is to have the hyperlink carry over into the pdf, and the typed out we

  • Problem with web service for document template

    Hi, I am trying to set up a web service to use with a word template (I use the template designer). The problem is that when I press the 'Test Page' button in the web service tool, I get an error : "Error retrieving URL to Web service test page ...'.

  • MacBook Pro 13" and X Plane 9

    Will a MacBook Pro 13" 2.3GHz be able to run X Plane 9 without any major problems (like slowing the computer or the game down)? I don't want to spend the money on the game if my computer won't be able to handle it smoothly. Will it take up a lot of s

  • I use quickbooks online and now that I have firefox 5 pdf doesnt work

    I have updated to Firefox 5 and now my Adobe PDF's don't print and has caused all my invoices to be out of line using another print source. Very frustrating, what is you alternative solution, I see many people are having this issue???This is the mess

  • Problems Running Flash MX

    I've been trying and trying and trying.... NOTHING IS WORKING! Please, if anyone knows why my flash program is no longer starting up, tell me before I go crazy! I recently got a new MacBook Pro and did the entire system transfer via the Firewire. Now