DataSet的自定义事件读取? [英] Custom Event for DataSet Read?

查看:61
本文介绍了DataSet的自定义事件读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个静态的线程安全类,其中DataSet作为属性。

当类被实例化为对象时,一些调用者将行添加到

DataSet中的DataTable。其他调用者读取DataSet。


当任何调用者读取DataSet时,我希望该对象删除DataTable中所有行的所有行。我想我想做一个自定义活动但是

我不知道在哪里/如何开始。帮助?


谢谢。

解决方案



" ;本地主机" < PR ******* @ cohort.ces>在消息中写道

news:cl ******************************** @ 4ax.com ...


我有一个静态的,线程安全的类,其中DataSet作为属性。
当类被实例化为对象时,一些调用者将行添加到
DataSet中的DataTable。其他调用者读取DataSet。

当任何调用者读取DataSet时,我希望该对象删除DataTable中的所有行。我想我想做一个自定义活动但是我不知道在哪里/如何开始。帮助?




如果由我决定,我会隐藏数据集属性,并使其可访问

仅来自我自己定义的方法...


例如:


公共类CustomDataSet

{

private System.Data.Dataset _myDataset;

public CustomDataSet()

{

myDataSet = new System.Data.DataSet();

}


//公共函数的一个示例可能是:

public bool FillDataSet(System.Data.DataAdapter adapter)

{

//在这里做任何你想做的事情......

// ....

返回false;

}


public DataRow GetRow(int index)

{

DataRow ret = _myDataset。 Tables [0] .Rows [index];

//在这里做任何你想做的事,例如:

_myDataset.Tables [0] .Rows.Clear();

返回ret;

}

}


或者您可能会发现定义更强大CLA ss索引器用于获取某些行中的行

,同时您仍然可以控制对

隐藏数据集的访问。




这不是我所说的。感谢您的回复,

虽然。


我没有使用DataAdapters做任何事情。


我需要完成的是私有DataSet的一种方式,

作为静态类的属性存在(通过公共访问

类的实例时重新创建,以便每个调用者获得一个新的DataSet。


谢谢。


2004年2月25日星期三23:09:43 +0200,hOSAM

< bk ************** *******@yahoo.com>写道:


" localhost" < PR ******* @ cohort.ces>在消息中写道
新闻:cl ******************************** @ 4ax.com ..。< blockquote class =post_quotes>
我有一个静态的,线程安全的类,其中DataSet作为属性。
当类被实例化为一个对象时,一些调用者将行添加
到一个DataSet中的DataTable。其他调用者读取DataSet。

当任何调用者读取DataSet时,我希望该对象删除DataTable中所有行的
。我想我想制作一个自定义活动
,但我不知道在哪里/如何开始。帮助?
如果由我决定,我会隐藏数据集属性,并使用我自己定义的方法将其设为



...

公共类CustomDataSet
私有System.Data.Dataset _myDataset;

public CustomDataSet()
{
myDataSet = new System.Data.DataSet();
}
//公共函数的一个示例可能是:
public bool FillDataSet(System.Data .DataAdapter适配器)
//
//做任何你想做的事情......
// ....
返回false;
}

public DataRow GetRow(int index)
{DataRow ret = _myDataset.Tables [0] .Rows [index];
//在此处做任何你想做的事,例如:
_myDataset.Tables [0] .Rows.Clear();
return ret;
}


或者您可能会发现定义类更健壮
的索引器获取某些indecies的行,而您仍然可以控制对隐藏数据集的访问






您好localhost,


如果是这样,你不能在你的房产''获得'中创建一个新的数据集。方法?喜欢

这个:


公共类yourclass

{

私有DataSet _ds;


公共DataSet数据集

{

get

{

if(something你想要的)

{

DataSet ds = new DataSet();

//对你的新数据集执行某些操作

返回ds;

}


}

设定

{

_ds = value;

}

}

}


在此解决方案中,你的公共数据集当某些条件满足时,属性将创建一个新的数据集




=================== ======================

感谢您的耐心与合作。如果您有任何疑问或

担忧,请随时将其发布在小组中。我正准备等待

的帮助。


祝你好运,

Jeffrey Tan

Microsoft在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有赋予任何权利。



I have a static, thread-safe class with a DataSet as a property.
When the class is instanced into an object, some callers add rows to a
DataTable in the DataSet. Other callers read the DataSet.

When any caller reads the DataSet, I want the object to delete all of
the rows in the DataTable. I think I want to make a custom event but
I don''t know where/how to get started. Help?

Thanks.

解决方案


"localhost" <pr*******@cohort.ces> wrote in message
news:cl********************************@4ax.com...


I have a static, thread-safe class with a DataSet as a property.
When the class is instanced into an object, some callers add rows to a
DataTable in the DataSet. Other callers read the DataSet.

When any caller reads the DataSet, I want the object to delete all of
the rows in the DataTable. I think I want to make a custom event but
I don''t know where/how to get started. Help?



If it is up to me, I would hide the dataset property, and make it accessible
only from my own defined methods...

for example:

public class CustomDataSet
{
private System.Data.Dataset _myDataset;
public CustomDataSet()
{
myDataSet = new System.Data.DataSet( );
}

// One example for a public function might be:
public bool FillDataSet(System.Data.DataAdapter adapter)
{
// Do whatever you wish here..
// ....
return false;
}

public DataRow GetRow(int index)
{
DataRow ret = _myDataset.Tables[ 0 ].Rows[ index ];
// Do whatever you wish here, for example:
_myDataset.Tables[ 0 ].Rows.Clear( );
return ret;
}
}

Or you might find it more robust to define class indexers for getting rows
at certain indecies, while you will still be able to control access to your
hidden dataset.




That is not quite what I am talking about. Thanks for the response,
though.

I''m not doing anything with DataAdapters or anything like that.

What I need to accomplish is a way for the private DataSet, which
exists as a property on the static class (accessed through a public
"get"), to be recreated each time a caller gets an instance of the
class so each caller gets a new DataSet.

Thanks.

On Wed, 25 Feb 2004 23:09:43 +0200, "hOSAM"
<bk*********************@yahoo.com> wrote:


"localhost" <pr*******@cohort.ces> wrote in message
news:cl********************************@4ax.com.. .


I have a static, thread-safe class with a DataSet as a property.
When the class is instanced into an object, some callers add rows to a DataTable in the DataSet. Other callers read the DataSet.

When any caller reads the DataSet, I want the object to delete all of the rows in the DataTable. I think I want to make a custom event but I don''t know where/how to get started. Help?
If it is up to me, I would hide the dataset property, and make it


accessibleonly from my own defined methods...

for example:

public class CustomDataSet
{
private System.Data.Dataset _myDataset;
public CustomDataSet()
{
myDataSet = new System.Data.DataSet( );
}

// One example for a public function might be:
public bool FillDataSet(System.Data.DataAdapter adapter)
{
// Do whatever you wish here..
// ....
return false;
}

public DataRow GetRow(int index)
{
DataRow ret = _myDataset.Tables[ 0 ].Rows[ index ];
// Do whatever you wish here, for example:
_myDataset.Tables[ 0 ].Rows.Clear( );
return ret;
}
}

Or you might find it more robust to define class indexers for getting rowsat certain indecies, while you will still be able to control access to yourhidden dataset.





Hi localhost,

If so, can''t you create a new dataset in your property''s "get" method? Like
this:

public class yourclass
{
private DataSet _ds;

public DataSet dataset
{
get
{
if(something you want)
{
DataSet ds=new DataSet();
//do something to your new dataset
return ds;
}

}
set
{
_ds=value;
}
}
}

In this solution, your public "dataset" property will create a new dataset
when some condition meets.

=========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


这篇关于DataSet的自定义事件读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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