I want to know how to acess the table8_sorted outside of the for loop
when I try to use it I get error
does not exists in current context
//--------------------------------------------------------------------------------------------
DataTable table8; //table8 used for sorting and then later for plotting
table8 = table7.Copy(); //table7 is the unsorted table
// cloning table8 is cloned to change the type of columns
DataTable dtSorted = table8.Clone();
for (int w = 0; w < table8.Columns.Count; w++)
{
dtSorted.Columns[w].DataType = typeof(Double);
}
foreach (DataRow row in table8.Rows)
{
dtSorted.ImportRow(row);
}
// sorting dtSorted to get table8_sorted (sorted table)
for (int loop = 0; loop < dtSorted.Columns.Count; loop++)
{
DataView dataview = dtSorted.DefaultView;
dataview.Sort = dtSorted.Columns[loop].ColumnName;
DataTable table8_sorted = dataview.ToTable();
//how to acess this out side of the loop
}
//Does not exists in current context
table8_sorted.Columns.Add("plot", typeof(double));
double terms = table8_sorted.Rows.Count;
int t = 1;
for (int i = 0; i < terms; i++)
{
double ap;
ap = (t - 0.3) / (terms + 0.4);
table8_sorted.Rows[i]["plot"] = ap;
t++;
}
Loading

VulpesPosted May 27, 2014, 2:21 PM
Palle TechnologiesPosted Jun 16, 2014, 12:17 PM
DataTable table8_sorted=null;
for (int loop = 0; loop < dtSorted.Columns.Count; loop++)
{
DataView dataview = dtSorted.DefaultView;
dataview.Sort = dtSorted.Columns[loop].ColumnName;
table8_sorted = dataview.ToTable();
//how to acess this out side of the loop
}
Farhan ShariffPosted May 28, 2014, 3:47 AM
Farhan ShariffPosted May 27, 2014, 12:27 PM
here also table1 rows[Par Name] are compared with table2 [columns] and new table is buit which is sorted... I want to follow something like this but I have only one final table which I have to sort
VulpesPosted May 27, 2014, 12:16 PM
Otherwise you have to have a primary sort column and the remaining columns are then subsidiary to that.
Farhan ShariffPosted May 27, 2014, 12:04 PM
VulpesPosted May 27, 2014, 12:01 PM
Farhan ShariffPosted May 27, 2014, 11:56 AM
VulpesPosted May 27, 2014, 11:49 AM
Sorting first takes place on the first column.
If any values in the first column are the same, it then sorts those rows on the second column and so on.
It can't, of course, sort all columns simultaneously unless values are to be moved between rows.
Farhan ShariffPosted May 27, 2014, 11:32 AM
Farhan ShariffPosted May 27, 2014, 11:13 AM
VulpesPosted May 27, 2014, 11:10 AM
CON_RES:RES_ADCI2_N_(ADCI2_N)@ADCI2_N[1]
and the Expression property parser doesn't like that because it ends with a square bracket which is used to 'escape' column names which contain non-alphanumeric characters.
Fortunately, you can also escape them using a pair of back ticks so try this instead:
string expr = "Convert(`" + dc.ColumnName + "`,'System.Double')";
Farhan ShariffPosted May 27, 2014, 10:53 AM
http://imgur.com/ST8jMAR
VulpesPosted May 27, 2014, 10:47 AM
for(int i = 0; i < count; i++)
{
DataColumn dc = table7.Columns[i];
string name = "dbl_" + dc.ColumnName; // prefix with dbl_
string expr = "Convert(" + dc.ColumnName + ",'System.Double')";
MessageBox.Show(expr);
table7.Columns.Add(name, typeof(double), expr);
sort += name + ",";
}
Farhan ShariffPosted May 27, 2014, 10:44 AM
VulpesPosted May 27, 2014, 10:43 AM
When I put that column name into a little model I made, it works fine.
Is :RES_ADCI2_N_ the actual name of a column or is there something before the colon and/or after the final underscore?
Farhan ShariffPosted May 27, 2014, 10:36 AM
Syntax error: Missing operand after ':RES_ADCI2_N_' operator.
VulpesPosted May 27, 2014, 10:24 AM
Farhan ShariffPosted May 27, 2014, 9:54 AM
VulpesPosted May 27, 2014, 9:49 AM
Farhan ShariffPosted May 27, 2014, 9:15 AM
I am cloning it to change its columns data type (to double) so -ve values are also considered and after cloning I thought of Sorting it in Asc order.
Is it possible to sort the data after cloning when I am adding the data.
VulpesPosted May 27, 2014, 9:12 AM
In fact you're doing exactly what you were doing before except now the variable is declared external to the for loop, not within it.
Farhan ShariffPosted May 27, 2014, 8:59 AM
dataview.ToView will it not change the datatable
when i checked
table8_sorted.Columns.Add("plot", typeof(double)); //sorting is undone
VulpesPosted May 27, 2014, 8:55 AM
Farhan ShariffPosted May 27, 2014, 8:41 AM
VulpesPosted May 27, 2014, 8:36 AM
Then in the for loop assign to that variable not a variable which is local to the for loop.