How to dynamically convert between Types?
-
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
-
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
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 )
-
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 )
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