I want to know how to write expression in data table to concatenate two integer type columns. Because when i try with '+' it adds the two integers.
Thanks in advance.
I want to know how to write expression in data table to concatenate two integer type columns. Because when i try with '+' it adds the two integers.
Thanks in advance.
If you want to set the expression of the result column. try this.
DataTable table = new DataTable();
table.Columns.Add("OrderCount",typeof(int));
table.Columns.Add("OrderPrice",typeof(int));
table.Rows.Add(new object[] { 1, 1 });
table.Rows.Add(new object[] { 2, 3 });
table.Rows.Add(new object[] { 4, 5 });
table.Columns.Add("Result", typeof(string));
table.Columns["Result"].Expression = "Convert(OrderCount, 'System.String') + OrderPrice";
The example:
int a = 1;
int b = 2;
var asInt = a + b; // asInt is now 3
var asString = a.ToString() + b.ToString() // asString is now "12"
var asStringAlt = String.Format("{0}{1}", a, b); // alternate method as suggested