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. General Programming
  3. C#
  4. How to dynamically convert between Types?

How to dynamically convert between Types?

Scheduled Pinned Locked Moved C#
questionhelptutorial
3 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.
  • S Offline
    S Offline
    Subrahmanyam K
    wrote on last edited by
    #1

    Hi Friends, Please help me for the below requirement. Note: Typed Datasets are considered for the requirement. Here, LookupTableDataSet Typed Dataset consists of the Agency and Authority DataTables. I have two methods as given below. public Int32 GetRowsInTable(String tableName) { Int32 result = 0; LookupTableDataSet ds = new LookupTableDataSet(); **_System.Data.DataTable dataTable = Fill(ds.Tables[tableName]); result = dataTable.Rows.Count;_** return result; } public LookupTableDataSet.AgencyDataTable Fill(LookupTableDataSet.AgencyDataTable dtAgency) { AgencyTableAdapter adapter = new AgencyTableAdapter(); adapter.Fill(dtAgency); return dtAgency; } public LookupTableDataSet.AuthorityDataTable Fill(LookupTableDataSet.AuthorityDataTable dtAuthority) { AuthorityTableAdapter adapter = new AuthorityTableAdapter(); adapter.Fill(dtAuthority); return dtAuthority; } 1. GetRowsInTable(String tableName) should return the row count for the table name sent as the parameter. 2. Fill() method is overloaded with different types of input parameters and return types. My requirement is that I have to pass the table name as the parameter to the GetRowsInTable() method to get the rows count for the table. As the Fill() method is overloaded with different types of input parameters how can I convert the input parameter to a specific type based on the tablename which was sent as a parameter to the GetRowsInTable() method? When I call the fill method as Fill(ds.Tables[tableName]), A System.Data.Dataset is being passed to the Fill() method where the fill method will accept only types LookupTableDataSet.AgencyDataTable or LookupTableDataSet.AuthorityDataTable. How can I dynamically convert the System.Data.DataSet to the required type to call the Fill() method. Also, please suggest me on dynamically casting the return types of Fill() methods. Statement throwing compilation errors were shown in Bold+Italic. Thanks in advance.

    Subrahmanyam K

    C 1 Reply Last reply
    0
    • S Subrahmanyam K

      Hi Friends, Please help me for the below requirement. Note: Typed Datasets are considered for the requirement. Here, LookupTableDataSet Typed Dataset consists of the Agency and Authority DataTables. I have two methods as given below. public Int32 GetRowsInTable(String tableName) { Int32 result = 0; LookupTableDataSet ds = new LookupTableDataSet(); **_System.Data.DataTable dataTable = Fill(ds.Tables[tableName]); result = dataTable.Rows.Count;_** return result; } public LookupTableDataSet.AgencyDataTable Fill(LookupTableDataSet.AgencyDataTable dtAgency) { AgencyTableAdapter adapter = new AgencyTableAdapter(); adapter.Fill(dtAgency); return dtAgency; } public LookupTableDataSet.AuthorityDataTable Fill(LookupTableDataSet.AuthorityDataTable dtAuthority) { AuthorityTableAdapter adapter = new AuthorityTableAdapter(); adapter.Fill(dtAuthority); return dtAuthority; } 1. GetRowsInTable(String tableName) should return the row count for the table name sent as the parameter. 2. Fill() method is overloaded with different types of input parameters and return types. My requirement is that I have to pass the table name as the parameter to the GetRowsInTable() method to get the rows count for the table. As the Fill() method is overloaded with different types of input parameters how can I convert the input parameter to a specific type based on the tablename which was sent as a parameter to the GetRowsInTable() method? When I call the fill method as Fill(ds.Tables[tableName]), A System.Data.Dataset is being passed to the Fill() method where the fill method will accept only types LookupTableDataSet.AgencyDataTable or LookupTableDataSet.AuthorityDataTable. How can I dynamically convert the System.Data.DataSet to the required type to call the Fill() method. Also, please suggest me on dynamically casting the return types of Fill() methods. Statement throwing compilation errors were shown in Bold+Italic. Thanks in advance.

      Subrahmanyam K

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      It looks like your method has custom types in it, I've nevr heard of an AuthorityDataTable before.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      S 1 Reply Last reply
      0
      • C Christian Graus

        It looks like your method has custom types in it, I've nevr heard of an AuthorityDataTable before.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        S Offline
        S Offline
        Subrahmanyam K
        wrote on last edited by
        #3

        Yes, you are right. I have custom types. LookupDataSet is a Typed Dataset and AuthorityDataTable is a Typed DataTable in that dataset which maps to the Authority database table at the back-end.

        Subrahmanyam K

        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