Hi,
I follow the solution mentioned in this link: http://sqlage.blogspot.in/2014/02/ssis-how-to-validate-excel-header.html
With the solution given there, Now, I am able to get the column headers of excel sheet and the table field names in the respective variables.
I am getting the table's field names of the table using below query,
SELECT Distinct
t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE SCHEMA_NAME(schema_id) in ('dbo')
and t.name = 'CRM'
This query returns the column names in alphabetical order. So I used customized excel query to make the order of the excel column headers in alphabetical order. But the code below never sorts the column values and goes for matching :(. So always the
columns, though are same, but returns result as not matching.. any thought on this?
If i get a help of sorting the values within the sysObject variable i guess i can make it, But in C# to sort the datatable values it requires column name to be provided upon which the sorting can happen. please help - Thank you!
OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter();
DataTable EDatatable = new DataTable();
ExcelAdapter.Fill(EDatatable, Dts.Variables["User::ExcelCRMColCounts"].Value);
int RC = 1;
String ColumnHeader;
MessageBox.Show(Dts.Variables["User::ExcelCRMColCounts"].Value.ToString());
forCRMh (DataRow DataRow in EDatatable.Rows)
{
if (RC == 1)
{
for (int i = 0; i < EDatatable.Columns.Count; i++)
{
ColumnHeader = DataRow[i].ToString();
Dts.Variables["User::FileHeader"].Value = Dts.Variables["User::FileHeader"].Value + "," + ColumnHeader;
}
}
RC += 1;
}
MessageBox.Show(Dts.Variables["User::FileHeader"].Value.ToString());
MessageBox.Show(Dts.Variables["User::TblCRMColCounts"].Value.ToString());
if ((Dts.Variables["User::FileHeader"].Value.ToString().Remove(0, 1)).TrimEnd(',') == Dts.Variables["User::TblCRMColCounts"].Value.ToString())
{
Dts.Variables["User::ExcelHeaderFlag"].Value = 1;
MessageBox.Show("Value are Matching");
}
else
{
Dts.Variables["User::ExcelHeaderFlag"].Value = 0;
MessageBox.Show("Value are not Matching");
}
Dts.TaskResult = (int)ScriptResults.Success;
--------------------------- Radhai Krish | Golden Age is no more far | --------------------------