1, to deal with what table column is unknown, so can't write column names;
2, will all the columns in the combobox datatable, according to the user to select the column accordingly;
3, will deal with good results in a new column, a new column name is original choose to modify the column name + "modified"
So I don't know how to implement the following effects:
Cases of table 1:
Name the amount
Zhang SAN 10
Li si 15
Cases of table 2:
Trade name for
Fan 60
The refrigerator 200
. There are many different table for different processing, such as the amount of the table a unified plus 10, unified price by 0.8 table 2, and so on,
String field 1=table 2. The columns [0]. Columnname;//or table, or from the interface values, methods, the meaning of word is a variable
String field 2=CBX target columns. SelectedItem. ToString ();
String field 3=2 + "modified";
Var query=the from p in dt. AsEnumerable ()
Select new
{
Field 1=p.F ield
Field 2=p.F ield
Field 3=p.F ield
};
//other code slightly
This is just a sample, has nothing to do with the actual effect, overall goal is to use in the select new variables as a field name, ask how to do?
CodePudding user response:
Write a code, you define a variable of type object, it refers to a "use the variable as a field name" object? This concept has never heard of c #, if you have "use the variable as a type name, code name" of the idea?CodePudding user response:
In c #, there are several dictionary extension type, ExpandoObject, for example, it is the key of type string dictionary, such asdynamic x=new ExpandoObject ();
X.a=100;
X.b="200";
Var y=(IDictionary) x;
Var u=(int) y (" x ");
Var v=(string) y [b];
Including Dictionary