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条件を守っていません。Executeメソッドは 4 つのDTSExecResult値のいずれかを返すことができるため、次のステートメントが必要になる可能性があります。Package.Execute()DTSExecResult.Successswitch

        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 に答える