Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将数据库中具有相同id的多行错误下载到xls文件中_C#_Asp.net_Sql_Sql Server - Fatal编程技术网

C# 将数据库中具有相同id的多行错误下载到xls文件中

C# 将数据库中具有相同id的多行错误下载到xls文件中,c#,asp.net,sql,sql-server,C#,Asp.net,Sql,Sql Server,我正在使用这段代码下载存储在sql数据库中fildemo表中的'data'和'data2'列中的错误 protected void helloGridView_SelectedIndexChanged(object sender, EventArgs e) { String connectionString = DAO.GetConnectionString(); String sqlQuery = String.Empty;

我正在使用这段代码下载存储在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文件中的不同行中。我该怎么做呢?

您是否尝试过
Response.Write(dr[“data”]+“\t\n\r”)

它似乎对我不起作用。尽管如此,谢谢!:)它确实含蓄地回答了这个问题。它也可以在我的机器上工作(尽管\r\n比\n\r\n好)。对于OP,您需要分享哪些不起作用,以获得更好的答案。