DataTable直接生成csv文件

//DataTable dt = ds.Tables[0];
            //HttpContext.Current.Response.Clear();

            //int daicount = dt.Rows.Count;

            //System.IO.StringWriter sw = new System.IO.StringWriter();

            //int iColCount = dt.Columns.Count;

            //for (int i = 0; i < iColCount; i++)
            //{

            //    sw.Write("/"" + dt.Columns[i] + "/"");

            //    if (i < iColCount - 1)
            //    {

            //        sw.Write(",");

            //    }

            //}

            //sw.Write(sw.NewLine);

            //foreach (DataRow dr in dt.Rows)
            //{

            //    for (int i = 0; i < iColCount; i++)
            //    {

            //        if (!Convert.IsDBNull(dr[i]))

            //            sw.Write("/"" + dr[i].ToString() + "/"");

            //        else

            //            sw.Write("/"/"");

            //        if (i < iColCount - 1)
            //        {

            //            sw.Write(",");

            //        }

            //    }

            //    sw.Write(sw.NewLine);

            //}

            //sw.Close();

            //HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);   //fileName文件名称

            //HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";

            //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

            //HttpContext.Current.Response.Write(sw);

            //HttpContext.Current.Response.End();

你可能感兴趣的:(ASP.NET,csv)