Sunday, 15 August 2010

c# - Read the start, end points from table and write value into text file based on those points -



c# - Read the start, end points from table and write value into text file based on those points -

i having below table has column name & start & end positions

name 0 25 25 30 b var flda = tbl in tblname.asenumerable() tbl.field<string>("name").trim().toupper() == "a" select new { = convert.toint32(order.field<string>(0)), = convert.toint32(order.field<string>(1)), }).firstordefault(); var fldb = tbl in tblname.asenumerable() tbl.field<string>("name").trim().toupper() == "b" select new { = convert.toint32(order.field<string>(0)), = convert.toint32(order.field<string>(1)), }).firstordefault(); //flda contains value = 0 & = 25 //fldb contains value = 25 & = 30

now writing text below

var file = new system.io.streamwriter("filepath"); file.writeline(string.format("{0,-" + (flda.to - flda.from).tostring() + "}{1,-" + (fldb.to - fldb.from).tostring() + "}", "hello-a", "helloooo-b");

is right approach write formatted text file.?

you can - have written query set in dictionary , can keys using name or create generic dump anything:

enumerablerowcollection<datarow> rowcollection = dataset.tables[0].asenumerable(); //conert dictionary var result = (from row in rowcollection select new { = convert.toint32(row.field<string>(0)), = convert.toint32(row.field<string>(1)), name = row.field<string>(2) }).todictionary(s => s.name); var file = new system.io.streamwriter("filepath"); foreach (var info in result) { // data.key name in table file.writeline(string.format("{0,-" + (data.value.to - data.value.from).tostring() + "}")); }

c# linq c#-4.0

No comments:

Post a Comment