【问题标题】:Exporting grid view data into Excel将网格视图数据导出到 Excel
【发布时间】:2012-10-17 09:41:08
【问题描述】:

将 Visual Studio 2010 与 Server Management Studio 2008 结合使用 我制作了一个功能,教师可以通过该功能查看所有年份的所有学生的成绩:

通过下拉选择,它在网格视图中显示数据,并带有一个按钮,教师可以在 Excel 工作表中查看选择。对于某些选择,数据量很大,因此需要时间。

现在我的客户不想在页面中显示网格视图,而是根据下拉选择直接导出到 Excel。

任何人都可以帮助我做到这一点.. 它会使我的页面加载速度更快吗?

【问题讨论】:

  • 我把可见属性改成了false..但是不知道会不会减少加载时间..?

标签: c#-4.0 export-to-excel


【解决方案1】:

首先在 ssms 中编写存储过程来检索数据。 应该是这样的

   CREATE PROCEDURE [Retrieveresult] (@selectedfield nvarchar(50))
   AS  
   BEGIN  
   select * from students where condition=@selectfield
   END  

然后在视觉工作室

   oConn = new SqlConnection();
   oConn.ConnectionString = "your connection string"
   SqlCommand command = new SqlCommand("Retrieveresult");
    command.CommandType = System.Data.CommandType.StoredProcedure;
     oConn.Open();
   command.Parameters.Add(new SqlParameter("@selectfield", System.Data.SqlDbType.nvarchar(50))); 
    command.Parameters["@selectfield"].Value="selected value from gridview"
   IDataReader oDr;
    oDr=command.executereader();
  while(oDr.read())
     {
       Get the corresponding values in the objects 
      }

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多