0

我使用 SQL Server 2012 和 Visual Studio 2012。我在 C# 中有以下代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.SqlServer.Dts.Runtime;


namespace ssis_project
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            /*
          SqlConnection con = new SqlConnection(@"Data Source=NICK-PC;Initial Catalog=ssis_project;Integrated Security=True;");
          SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) from users where username='" + userBox.Text + "' and password ='" + passBox.Text + "'", con);
            */

            Microsoft.SqlServer.Dts.Runtime.Application myAplication = new Microsoft.SqlServer.Dts.Runtime.Application();
            Package myPackage = myAplication.LoadPackage(@"D:\SSIS\ssis_project\ssis_project\users.dtsx", null);


            myPackage.Variables["User::uservar"].Value = this.userBox.Text;
            myPackage.Variables["User::passvar"].Value = this.passBox.Text;

            Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = myPackage.Execute();
            if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success)

                 MessageBox.Show("You are logged as:  " + myPackage.Variables["User::uservar"].Value + " with pass:  " + myPackage.Variables["User::passvar"].Value);

            //DataTable dt = new DataTable();
           //sda.Fill(dt);
           /*
            if (dt.Rows[0][0].ToString() == "1")


                MessageBox.Show("You are logged as:  " + userBox.Text + " with pass:  " + passBox.Text );

            else 
            {
            MessageBox.Show("Please Check your Username and Password");
            }*/
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

如果我使用与 SQL Server 的连接,它正在工作并向我展示

MessageBox.Show("You are logged as: " + userBox.Text + " with pass: " + passBox.Text );

或者

MessageBox.Show("Please Check your Username and Password");

如果我加载 SSIS 包,它不会向我显示该消息。

Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = myPackage.Execute();我认为我需要一个if但我不知道该怎么做之后。请帮我。

4

1 回答 1

1

您的if声明没有保护Package.Execute()返回任何其他内容的条件DTSExecResult.Success。由于Execute方法可以返回四个DTSExecResult值中的任何一个,因此您可能需要一个switch语句:

        DTSExecResult results = myPackage.Execute();
        switch (results)
        {
            case DTSExecResult.Success:
                // do something if the package works
                break;
            case DTSExecResult.Failure:
                // do something else if the package failed
                break;
            case DTSExecResult.Canceled:
                // do yet another something if the package was cancelled
                break;
            case DTSExecResult.Completion:
                // do something completely different if the package ran to completion
                break;
        }

一旦您知道实际返回值是什么,您就可以进一步排除故障。

于 2013-10-13T19:23:56.330 回答