我想将具有给定名称的列放入 DataColumn 对象中,以便可以迭代该列的行。我的代码如下。我在标记为 pseudocode 的行中做了什么替换?
我想您可以放心地忽略所有这些代码并立即阅读 main() 方法代码。具体来说,去线 -
DataColumn dc = getColumn("YourColumnName"); //PSEUDOCODE
代码是 -
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Xml;
using System.Data.OleDb;
namespace ST_54125473205c4f38b466c43a15bc9d79.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()
{
// TODO: Add your code here
Dts.TaskResult = (int)ScriptResults.Success;
OleDbDataAdapter oleDA = new OleDbDataAdapter();
DataTable dt = new DataTable();
DataColumn col = null;
DataRow row = null;
string strMsg = null;
oleDA.Fill(dt, Dts.Variables["myADO_Recordset"].Value);
foreach (DataRow dtRow in dt.Rows)
{
DataColumn dc = getColumn("YourColumnName"); //PSEUDOCODE
var field1 = dc.ColumnName;
MessageBox.Show(field1);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}