日期:2014-05-18 浏览次数:20906 次
StringBuilder strb = new StringBuilder(); foreach(DataRow dr in dt.Rows) { if(strb.Length > 0) { strb.Append("#"); } strb.Append(string.format("{0},{1},{2}", dr["bh"].ToString(), dr["name"].ToString(), "Zy")); } string result = strb.ToString();
------解决方案--------------------
SqlConnection conn = ......; conn.Open(); SqlDataAdapter ada = new SqlDataAdapter("select bh, name from v", conn); var dtbl = new DataTable(); ada.Fill(dtbl); var result = string.Join("#", Array.ConvertAll(dtbl.Select(), v1 => string.Join(",", v1.ItemArray) + ",Zy"));