0

我目前正在使用这段代码来下载存储在 sql 数据库中 fildemo 表中的“data”和“data2”列中的错误。

  protected void helloGridView_SelectedIndexChanged(object sender, EventArgs e)
        {
            String connectionString = DAO.GetConnectionString();
            String sqlQuery = String.Empty;


            using (SqlConnection con = new SqlConnection(connectionString))
            {
                con.Open();
                sqlQuery = "select data,data2 from filedemo where id=@id";
                SqlCommand cmd = new SqlCommand(sqlQuery, con);
                cmd.Parameters.AddWithValue("id", surgicalGridView.SelectedRow.Cells[1].Text);
                SqlDataReader dr = cmd.ExecuteReader();

                if (dr.Read())
                {

                    HttpContext.Current.Response.ClearContent();
                    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + dr["name"].ToString() + ".xls");
                    HttpContext.Current.Response.ContentType = "application/excel";
                    Response.Charset = "";
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.Write(dr["data"] + "\t");
                    Response.Write(dr["data2"] + "\t");
                    Response.End();

                }
            }

        }

我想从具有相同 ID 的不同行中提取错误,并将它们存储在 excel 文件中的单独行中。我该怎么做呢?

4

1 回答 1

0

你试过Response.Write(dr["data"] + "\t\n\r");吗?

于 2013-03-17T23:53:18.900 回答