2012-10-17 30 views
0

使用Visual Studio 2010 Server Management Studio中2008年我做了一個功能,通過它教師可以看到所有年份的所有學生的成績:導出網格視圖的數據導入Excel

通過下拉菜單選擇它顯示的數據網格視圖,並有一個按鈕供教師在Excel工作表中查看選擇。對於一些選擇有很多數據,所以需要時間。

現在我的客戶端不希望在頁面中顯示網格視圖,而是根據下拉選擇直接導出到Excel中。

任何人都可以幫助我做到這一點,它會讓我的網頁加載速度更快一點嗎?

+0

我更改屬性可見false..But我不知道這是否會降低其加載時間..? –

回答

1

首先在ssms中寫入存儲過程以檢索數據。 應該是這樣

CREATE PROCEDURE [Retrieveresult] (@selectedfield nvarchar(50)) 
    AS 
    BEGIN 
    select * from students where [email protected] 
    END 

然後在VisualStudio中

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 
     } 
+0

我沒有這樣的連接。但是,謝謝你的回覆.. –

+0

給你的連接字符串爲你的分貝,請參考這個給連接-http://www.connectionstrings.com/mysql – SRIRAM

+0

你能幫我在這...因爲我發現我的加載問題是不是因爲這個,而是因爲我的一些編碼循環..http://stackoverflow.com/questions/12947870/bindingdata-into-table-according-to-selection-in-the-dropdowns –