2014-10-09 14 views
0

我正在開發一個銀行應用程序,其中編寫了一個幫助程序類。
什麼情況是,每當我連續5〜7次以上,按刷新按鈕,它給了我這個錯誤:Fill: SelectCommand.Connection property has not been initialized.在刷新頁面上連續選擇命令錯誤

任何機構可以指定我在我的代碼,或什麼,我更可以做很想念爲了更好地執行沒有任何錯誤?

我的輔助類功能:

private static OdbcCommand cmd; 
    private static OdbcDataAdapter da; 
    private static DataTable dt; 


    public static void GetDataInDataGrid(string sp_Name, GridView gv) 
    { 
     dt = new DataTable(); 
     try 
     { 
      using (cmd = new OdbcCommand(sp_Name)) 
      { 
       cmd.Connection = Connection.ConnString.ConnectionString; 
       using (da = new OdbcDataAdapter(cmd)) 
       { 

        da.Fill(dt); 
        if (dt.Rows.Count > 0) 
        { 
         gv.DataSource = dt; 
         gv.DataBind(); 
        } 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 
    } 

錯誤在下面的代碼出現,在throw語句

try 
    { 
    if (!IsPostBack) 
    { 
     herlperUtility.GetDataInDataGrid("{ CALL asp_sp_GetDataForSupervisor }", this.gvSuperviseDataGrid); 
     if (this.gvSuperviseDataGrid.DataSource == null) 
     { 
     this.divFailure.InnerText = "No Records Found!!!"; 
     this.divFailure.Attributes.Add("style", "display:block;margin-top:20px;"); 
     } 
    } 
    } 
    catch (Exception ex) 
    { 
    throw ex; 
    } 
+0

這肯定是很多代碼。現在錯誤發生在哪裏? – Marco 2014-10-09 07:02:41

回答

1

using (cmd = new OdbcCommand(sp_Name,Connection.ConnString.ConnectionString)) 

地質儲量

using (cmd = new OdbcCommand(sp_Name)) 
      { 
       cmd.Connection = Connection.ConnString.ConnectionString;