如何针对键入的数据集执行自定义命令 [英] How to execute a custom command against a typed dataset
问题描述
我想对使用数据集设计器创建的类型化数据集执行自定义命令。为此,我需要获得对底层连接的引用,对吧?如何去做这个?
I want to execute a custom command against a typed dataset I created using the dataset designer. For this I need to get a reference to the underlying connection, right? How to go about this? In which autogenerated file can I find the connection?
推荐答案
您可以在设计器中设置TableAdapter的ConnectionModifier属性,默认为到内部,所以你可以使用它在同一个项目/程序集,将其更改为公共,并使用它无处不在你需要它。或者一个更好的aproach将创建一个部分类基于您的TableAdapter名称/命名空间,并封装在同一个表适配器内的逻辑:
You can set the ConnectionModifier property of the TableAdapter in the designer, is defaulted to Internal, so you can use it in the same project/assembly, change it to Public and use it everywhere you need it. Or a better aproach will be create a partial class based in your TableAdapter name/namespace and encapsulate the logic within the same table adapter:
// if DataSet name is Sales and Table name is Order
namespace SalesTableAdapters // use full namespace here
{
public partial class OrderTableAdapter
{
public void CustomCommand()
{
// here you can use the property this.Connection
// and execute your command
}
}
}
这篇关于如何针对键入的数据集执行自定义命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!