Im在SSIS包內部工作。我有一些C#腳本用於將表名放入對象變量(訪問表)中。該代碼連接到Access數據庫並循環查找將其名稱變爲變量的表。C#將'['']'添加到TableName的變量中使用
分配去如下:
using System;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace ST_9b2714c55db14556be74ca92f345c4e3.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
public void Main()
{
Variables varCollection = null;
DataTable schemaTables = null;
ArrayList tableNames = new ArrayList();
Dts.VariableDispenser.LockForWrite("User::AccessTables");
Dts.VariableDispenser.GetVariables(ref varCollection);
using (OleDbConnection connection = new OleDbConnection(Dts.Connections["TE030698.Bases"].ConnectionString.ToString()))
{
string[] restrictions = new string[4];
restrictions[3] = "Table";
connection.Open();
schemaTables = connection.GetSchema("Tables", restrictions);
}
foreach (DataRow row in schemaTables.Rows)
{
foreach (DataColumn column in schemaTables.Columns)
{
if (column.ColumnName.ToUpper() == "TABLE_NAME")
{
tableNames.Add(row[column].ToString());
}
}
}
varCollection["User::AccessTables"].Value = tableNames;
Dts.TaskResult = (int)ScriptResults.Success;
問題是一些表開始與數字或包含空格。所以我需要把名字保存在[]中。 2012年是一張桌子,但我需要它[2012]。我怎麼能改變C#代碼來做到這一點?
我對C#很新,所以任何建議將不勝感激。由於
http://mattgemmell.com/2008/12/08/what-have-you-tried/ – 2012-04-12 16:30:11
埃姆,你寫 「[」 +姓名+ 「]」?我不確定問題是什麼。我能看到的唯一問題是命名空間。 – 2012-04-12 16:31:37
什麼是2012?我沒有看到它在上面的代碼? – MoonKnight 2012-04-12 16:32:06