Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Create a generic class which can store the values in get set properties from the dataset or the data table where get set values can be accessible from any form in windows c#

string from
{
get;set;
}
string val1
{
get;set;
}
string val2
{
get;set;
}

data table is in the form of



formval val1 val2 val3 val4
form 1 0 0 0
form1 2 0 1 1
form2 1 2 0 1
form3 5 0 1 0




how do i get the data table values in the get set properties form the generic class


So that i can use this property to enable disable buttons...
Posted
Updated 8-Oct-13 4:00am
v2
Comments
Mart Rijkers 8-Oct-13 16:31pm    
I see you edited the question. If you do so, noone that tried to answer sees the edit. You can better add a comment to get more help.
BillWoodruff 8-Oct-13 18:16pm    
I can't understand your question. What do the numbers after your database entries, like "form3 5 0 1 0" refer to ?

You can create Classes at run-time in C#, and then create instances of them to use, but doing that is a very advanced use of Reflection.
MuhammadUSman1 9-Oct-13 0:57am    
What you want to get from datatable?
DataRows, DataColumns, or specific field data?

C#
private DataTable dataTable;

public DataTable myTable
{
  get {return dataTable;}
  set {datTable=value;}
}
 
Share this answer
 
Ofcourse you can fill different strings but
if you want specific values, you can create methods to do this in your class. You can set the datatable with the public object as in solution 1. After you have loaded the DataTable in the private DataTable object "dataTable" you can use this in your methods in the class.

For example:
C#
public string Value1(int FormNumber)
{
  return dataTable.Rows[FormNumber]["val1"].ToString();
}


I did NOT test this code. If you do not know the FormNumber, you can write a loop to find the form using a text description
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900