现有如下语句创建的两张表:CREATE TABLE [dbo].[分销业绩] (
[id] [int] NOT NULL ,
[部门] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[子部门] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[username] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[日期] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[二级商] [nvarchar] (80) COLLATE Chinese_PRC_CI_AS NULL ,
[协议额] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[产品] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[数量] [int] NULL ,
[价格] [float] NULL ,
[金额] [float] NULL ,
[备注] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GOCREATE TABLE [dbo].[产品] (
[id] [int] NOT NULL ,
[fid] [int] NULL ,
[index1] [int] NULL ,
[name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[规格] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[price] [float] NULL ,
[单位] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[是否积分] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO在asp.net中是datagrid绑定地分销业绩表,按产品表动态添加列,深成如下图的excel导出:
部门 办事处 分销代表 二级商  类别 一级商 协议额(万元) 月份 品种1  品种n 合计
---------------------------------------------------------------------------
销售部  北京   张三   xx公司  企业客户 xx公司   50 2006-2  单价20数量10 合计200.......   合计 n元 
分销业绩表中有2006年3万行数据,产品中有20个品种,数据采用手写标记填充单元格显示,现在的问题是在导出进行到一半时,服务器就停止了响应,其它机器也无法打开站点上的页面,请问如何提高这种页面的工作效率,求例子或思路

解决方案 »

  1.   

    补充:产品单元格的填充是在DataGrid ItemDataBound事件中进行的
      

  2.   

    在web.config里把数据库连接时间设的N长
      

  3.   

    在极端状态下我要把3万记录输出至excel,我做的是维护工作,数据库结构是不可以动的,所以郁闷阿,先谢了
      

  4.   

    如果是导出Execle不应该用 web 来做,性能太低了.
    如果数据量大的话,不推荐使用 DataGrid,性能也是相当的低.
    DataGrid 分页功能需要把所有数据全部读出道 DataSet 中.....
    建议使用定制的分页存储过程
      

  5.   

    回GaoGaoWuDi() :
    动态添加列:
     Comm1.CommandText = "select id,name,单位,规格 from [产品] order by index1" ' where id=" & dr2.Item(0).ToString()
            dr1 = Comm1.ExecuteReader()
            Do While dr1.Read()            str9 = dr1.Item("name").ToString() & "(" & dr1.Item("规格").ToString() & ")"
                str8 = str8 & "," & DataGrid1.Columns.Count & ":" & dr1.Item(0).ToString()            bc = New BoundColumn
                bc.HeaderText = "<table width='100%'  border='1' cellspacing='0' cellpadding='0'><tr align='center'><td colspan='3'>" & str9 & "</td></tr><tr align='center'><td>数量(" & dr1.Item(2).ToString() & ")</td><td>价格(元)</td><td>金额(元)</td></tr></table>"
                bc.ItemStyle.Wrap = False
                bc.HeaderStyle.Wrap = False
                DataGrid1.Columns.Add(bc)        Loop
            dr1.Close()
            Conn1.Close()
      

  6.   

    数据源绑定:
    Comm2.CommandText = "select 部门,username,二级商,子部门,日期,协议额 from [分销业绩] where  部门='" & Request.QueryString("b") & "'  and [子部门]='" & Request.QueryString("b2") & "' and cast(日期+'-1' as datetime) between '" + Request.QueryString("st") + "' and '" + Request.QueryString("sd") + "' order by 部门,子部门,日期"
    Ad2.SelectCommand = Comm2
            Ad2.Fill(Ds2, "products")
            DataGrid1.DataSource = Ds2.Tables("products")
      

  7.   

    数据填充: 
    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
            Dim fid As String
            Dim str7 As String
            Dim i9 As Integer        If Not (e.Item.ItemType = ListItemType.Header Or e.Item.ItemType = ListItemType.Footer) Then            Dim leap1 As Integer = 0
                For i9 = 0 To a1.Length - 1
                    a2 = Split(a1(i9), ":")
                    '计算产品数量及金额合计
                    Comm4.CommandText = "select sum(数量),sum(金额),CONVERT(decimal(10,2),价格) from [分销业绩] where username='" & e.Item.Cells(2).Text & "' and 二级商='" & e.Item.Cells(3).Text & "' and 协议额=" & e.Item.Cells(6).Text & " and 日期='" & e.Item.Cells(7).Text & "' and 产品='" & a2(1) & "'  group by CONVERT(decimal(10,2),价格)" 'and convert(decimal(10,4),价格)=" & e.Item.Cells(7).Text & " group by 价格"
                    'Response.Write(Comm4.CommandText & "<br>")                dr4 = Comm4.ExecuteReader
                    If dr4.Read() Then
                        leap1 = 1
                        e.Item.Cells(CInt(a2(0))).Text = "<table width='100%'  border='1' cellspacing='0' cellpadding='0'><tr align='center'><td>" & dr4.Item(0).ToString() & "</td><td class=xl24>" & Format(dr4.Item(2), "F2") & "</td><td class=xl24>" & Format(dr4.Item(1), "F2") & "</td></tr></table>"
                    Else
                        e.Item.Cells(CInt(a2(0))).Text = "<table width='100%'  border='1' cellspacing='0' cellpadding='0'><tr align='center'><td></td><td></td><td></td></tr></table>"
                    End If
                    dr4.Close()
                Next            '求合计
                Comm4.CommandText = "select sum(金额) from [分销业绩] where username='" & e.Item.Cells(2).Text & "' and 二级商='" & e.Item.Cells(3).Text & "' and 协议额=" & e.Item.Cells(6).Text & " and 日期='" & e.Item.Cells(7).Text & "'" ' and convert(decimal(10,4),价格)=" & e.Item.Cells(7).Text
                dr4 = Comm4.ExecuteReader
                If dr4.Read() Then
                    If dr4.Item(0).ToString() <> "" Then
                        e.Item.Cells(CInt(str6)).Text = Format(dr4.Item(0), "F2")
                        e.Item.Cells(CInt(str6)).Attributes.Add("class", "xl24")
                    End If
                End If
                dr4.Close()
    end sub
      

  8.   

    ...数据量那么大还多次排序.
    还是那句话,不建议你用DataGrid.
    问一下,你使用什么数据库?
    最好使用存储过程,能提高不少性能.
    你指服务器就停止了响应是指导出Execle还是查看的时候?
      

  9.   

    sql server导出停了,我这个结果不需要显示,是直接输出excel的
      re: 入行不久,不怎么会用存储过程,先寒自己下
      

  10.   

    ...直接输出excel,没必要使用DataGrid吧.
    直接输出不就好了,哪怕用最苯的方式,读一条输出一条.....
      

  11.   

    最好不要用web,用winfrom+多线程,怎么都不会死机得...
      

  12.   

    这是个b/s系统啊,by:
            Response.Clear()
            Response.Write("<HTML>")
            Response.Write("<HEAD>")
            Response.Write("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>")
            Response.Write("<meta name='ProgId' content='Excel.Sheet'>")
            Response.Write("<meta name='Generator' content='Microsoft Excel 11'>")
            Response.Write("<style>.xl24 {mso-number-format:'0\.00_ ';text-align:general;}.xl23{ mso-number-format:'\@';}")
            Response.Write("</style><title>二级商进货明细</title>")
            Response.Write("</HEAD>")
            Response.Write("<body>")        Response.Buffer = True
            Response.Charset = "GB2312" '设置了类型为中文防止乱码的出现 
            Response.AppendHeader("Content-Disposition", "attachment;filename=OutExcel.xls") '定义输出文件和文件名 
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312") ';//设置输出流为简体中文 
            Response.ContentType = "application/ms-excel" ';//设置输出文件类型为excel文件。 
            Page.EnableViewState = False
            Dim myCItrad As New System.Globalization.CultureInfo("ZH-CN", True)
            Dim oStringWriter As New System.IO.StringWriter(myCItrad)
            Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
            DataGrid1.RenderControl(oHtmlTextWriter)
            Response.Write(oStringWriter.ToString())        Response.Write("</HEAD>")
            Response.Write("</HTML>")
            Response.End()我只会这一种导出方式