0

好吧,这可能看起来很愚蠢。但是,我不知道如何在 Visual Studio 2008 中的 C# 中进行“导入”。我知道 java,但不知道 C#。目前,我没有时间阅读 ac# book。所以,我需要一些帮助才能做到这一点。

我试图在这里使用代码 - SSIS Getting Execute Sql Task result set object

DataTable dt = new DataTable();
OleDbDataAdapter oleDa = new OleDbDataAdapter();
oleDa.Fill(dt, Dts.Variables["User::objShipment"].Value);

我收到错误消息 - 找不到类型或命名空间名称“OledDbDataAdapter”(您是否缺少 using 指令或程序集引用?)

我试图做一个java风格的导入。但它失败了。

using System.Data.OleDb::OleDbDataAdapter

下面给出的完整代码 -


using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.OleDb;

namespace ST_LongCodeGoesHere.csproj
{

    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        #region VSTA generated code
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion

        //To see the comment here, look at beyond end of this code.

        public void Main()
        {
            // TODO: Add your code here
            DataTable table = new DataTable();
            OledDbDataAdapter oleDbA = new OleDbDataAdapter();
            Dts.TaskResult = (int)ScriptResults.Success;
        }
    }
}

评论是——

   /*
            The execution engine calls this method when the task executes.
            To access the object model, use the Dts property. Connections, variables, events,
            and logging features are available as members of the Dts property as shown in the following examples.
        To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
        To post a log entry, call Dts.Log("This is my log text", 999, null);
        To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);

        To use the connections collection use something like the following:
        ConnectionManager cm = Dts.Connections.Add("OLEDB");
        cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";

        Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

        To open Help, press F1.
    */
4

3 回答 3

3

在 C# 中,您不导入单个类型,而是导入整个命名空间。像这样的东西应该工作:

using System.Data.OleDb;

...

OleDbDataAdapter oleDa = new OleDbDataAdapter();

或者您可以像这样创建一个类型别名:

using OleDbDataAdapter = System.Data.OleDb.OleDbDataAdapter;

延伸阅读

于 2013-10-21T06:16:26.727 回答
0

看看这个http://msdn.microsoft.com/en-us/library/vstudio/wkze6zky.aspx

  • 您需要添加参考,然后才能使用它。
于 2013-10-21T06:23:15.430 回答
0

在解决方案下的解决方案资源管理器中找到“参考”并通过右键单击和“添加参考”添加 System.Data。您可能还希望将导入键入为: using System.Data.OleDb;

于 2013-10-21T06:17:53.407 回答