如何创建一个通用类,该通用类可以将数据表或数据集中的值获取到获取集属性中 [英] How to Create a Generic Class which can get the values from datatable or dataset into get set properties

查看:115
本文介绍了如何创建一个通用类,该通用类可以将数据表或数据集中的值获取到获取集属性中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个通用类,该类可以将值存储在数据集或数据表的get set属性中,可以在Windows c#中以任何形式访问get set值

来自
的字符串 {
get; set;
}
字符串val1
{
get; set;
}
字符串val2
{
get; set;
}

数据表的格式为



格式val1 val2 val3 val4
表格1 0 0 0
形式1 2 0 1 1
表格2 1 2 0 1
表格3 5 0 1 0




如何从通用类中获取数据集属性中的数据表值


这样我就可以使用此属性来启用禁用按钮...

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

推荐答案

private DataTable dataTable;

public DataTable myTable
{
  get {return dataTable;}
  set {datTable=value;}
}


当然,您可以填充不同的字符串,但
如果需要特定的值,则可以在类中创建方法来执行此操作.您可以像解决方案1中那样使用公共对象设置数据表.将数据表加载到私有数据表对象数据表"中后,可以在类的方法中使用它.

例如:
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:
public string Value1(int FormNumber)
{
  return dataTable.Rows[FormNumber]["val1"].ToString();
}



我没有测试此代码.如果您不知道FormNumber,则可以编写循环以使用文本描述查找表单



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


这篇关于如何创建一个通用类,该通用类可以将数据表或数据集中的值获取到获取集属性中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆