为SSIS编写自定义任务项(Task)之高级篇
2009-09-19 00:00:00 来源:WEB开发网6. 修改窗体代码
using System;
using System.Windows.Forms;
using Microsoft.SqlServer.Dts.Runtime;
namespace MySSISTaskSample
{
public partial class MyTaskEditor : Form
{
public MyTaskEditor()
{
InitializeComponent();
}
private TaskHost taskHost;
public MyTaskEditor(TaskHost host):this()
{
taskHost = host;//这里接受传递过来的宿主,其实就是那个MyXmlTask的实例
//读取属性
txtSource.Text = taskHost.Properties["Source"].GetValue(host).ToString();
txtOutput.Text = taskHost.Properties["Target"].GetValue(host).ToString();
txtxpath.Text = taskHost.Properties["Xpath"].GetValue(host).ToString();
txtDef.Text = taskHost.Properties["Namespacedefs"].GetValue(host).ToString();
}
private void btOk_Click(object sender, EventArgs e)
{
//写入属性
//TODO:这里还可以做得更好一些,例如添加验证代码
taskHost.Properties["Source"].SetValue(taskHost, txtSource.Text);
taskHost.Properties["Target"].SetValue(taskHost, txtOutput.Text);
taskHost.Properties["Xpath"].SetValue(taskHost, txtxpath.Text);
taskHost.Properties["Namespacedefs"].SetValue(taskHost, txtDef.Text);
//如果验证无法通过,则将窗体的DialogResult设置为None,阻止其退出
}
}
}
更多精彩
赞助商链接