我使用 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
但我不知道该怎么做之后。请帮我。