I have two DataTable -- 1.table1
2.table2
THESE ARE MY TWO
DATATABLES (visual c#)
table1
|Par Name| | Par #|-- |Units |--|LSL|--|USL |--|SKIP |
Diffusion |908513100 |- | 0 | 99.9| |0 |
Program |908514100 |- | 99.5 |999 | |0 |
(ADCQ2_P) |908533100 |- | 1000 | 0 | |0 |
table2
starttime | (ADCQ2_N) | Device | Diffusion | Program | (ADCQ2_P) |
11/7/2013 | SAF5100EL | 163 | -0.145712003 | -0.146583006 | 6.29
11/7/2013 | SAF5100EL | 84 | -0.137499005 | -0.137592003 | 6.21
11/7/2013 | SAF5100EL | 44 | -0.142690003 | -0.143250003 | 6.33
11/7/2013 | SAF5100EL | 164 | -0.139434993 | -0.140459001 | 6.23
11/7/2013 | SAF5100EL | 34 | -0.147183999 | -0.148519993 | 6.11
output should look like
table3
|Diffusion| | Program | (ADCQ2_P)
-0.145712003 - -0.146583006 - 6.29
-0.137499005 - -0.137592003 - 6.21
-0.142690003 - -0.143250003 - 6.33
-0.139434993 - -0.140459001 - 6.23
-0.147183999 - -0.148519993 - 6.11
here the columns in table2 which match the row names of table1(for instance here diffusion and program) have to be fetched from datatable2 and new DataTable3 has to be created and with sorted values of columns (Diffusion and Program)
I want to fetch only those column from table2 into table3 which match with table1 rows
The used the following code to build the tables
This is how I built the Datatable
using System;
using System.Data;
using Microsoft.VisualBasic.FileIO;
namespace ReadDataFromCSVFile
{
static class Program
{
static void Main()
{
string csv_file_path = @"C:\Matlab\Limits.csv";
DataTable table1 = GetDataTabletFromCSVFile(csv_file_path);
Console.WriteLine("Rows count:" + table1.Rows.Count);
Console.ReadLine();
}
private static DataTable GetDataTabletFromCSVFile(string csv_file_path)
{
DataTable table1 = new DataTable("Limits");
using (TextFieldParser csvReader = new TextFieldParser(csv_file_path))
{
csvReader.SetDelimiters(new string[] { "," });
csvReader.HasFieldsEnclosedInQuotes = true;
string[] colFields = csvReader.ReadFields();
foreach (string column in colFields)
{
DataColumn datecolumn = new DataColumn(column);
datecolumn.AllowDBNull = true;
table1.Columns.Add(datecolumn);
}
while (!csvReader.EndOfData)
{
string[] fieldData = csvReader.ReadFields();
//Making empty value as null
for (int i = 0; i < fieldData.Length; i++)
{
if (fieldData[i] == "")
{
fieldData[i] = null;
}
}
table1.Rows.Add(fieldData);
}
}
return table1;
}
[edit]Code block added - OriginalGriff[/edit]
[edit]Code block added, again - OriginalGriff[/edit]
table2
starttime |(ADCQ2_N) | Device | Diffusion | Program |
11/7/2013 SAF5100EL 163 -0.145712003 -0.146583006 -0.146583006
11/7/2013 SAF5100EL 84 -0.137499005 -0.137592003
11/7/2013 SAF5100EL 44 -0.142690003 -0.143250003
11/7/2013 SAF5100EL 164 -0.139434993 -0.140459001
11/7/2013 SAF5100EL 34 -0.147183999 -0.148519993
output should look like
table3 Product
|Diffusion| | Program |
-0.145712003 -0.146583006
-0.137499005 -0.137592003
-0.1 -0.143250003
-0.139434993 -0.140459001
-0.147183999 -0.148519993
here the columns in table2 which match the row names of table1(for instance here diffusion and program) have to be fetched from datatable2 and new DataTable3 has to be created and with sorted values of columns (Diffusion and Program)
I want to fetch only those column from table2 into table3 which match with table1 rows
The used the following code to build the tables
This is how I built the Datatable
using System;
using System.Data;
using Microsoft.VisualBasic.FileIO;
namespace ReadDataFromCSVFile
{
static class Program
{
static void Main()
{
string csv_file_path = @"C:\Matlab\Limits.csv";
DataTable table1 = GetDataTabletFromCSVFile(csv_file_path);
Console.WriteLine("Rows count:" + table1.Rows.Count);
Console.ReadLine();
}
private static DataTable GetDataTabletFromCSVFile(string csv_file_path)
{
DataTable table1 = new DataTable("Limits");
using (TextFieldParser csvReader = new TextFieldParser(csv_file_path))
{
csvReader.SetDelimiters(new string[] { "," });
csvReader.HasFieldsEnclosedInQuotes = true;
string[] colFields = csvReader.ReadFields();
foreach (string column in colFields)
{
DataColumn datecolumn = new DataColumn(column);
datecolumn.AllowDBNull = true;
table1.Columns.Add(datecolumn);
}
while (!csvReader.EndOfData)
{
string[] fieldData = csvReader.ReadFields();
//Making empty value as null
for (int i = 0; i < fieldData.Length; i++)
{
if (fieldData[i] == "")
{
fieldData[i] = null;
}
}
table1.Rows.Add(fieldData);
}
}
return table1;
}
[edit]Code block added - OriginalGriff[/edit]
[edit]Code block added, again - OriginalGriff[/edit]