2014-01-29 41 views
0

net.I在Visual Studio 2010中使用數據視圖進行設計.GridView和DetailsView運行時沒有問題。在FormView中我試圖用下面的代碼開發一個編輯模板:在ASP.net中更新formview

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" 
     onselecting="SqlDataSource1_Selecting" SelectCommand="SELECT * FROM [student]" 
     UpdateCommand="Update student set [email protected], [email protected], [email protected], [email protected] where [email protected]" > 
     </asp:SqlDataSource> 

我如下得到一個錯誤:

'ASP.default_aspx'不包含'SqlDataSource1_Selecting'的定義,並沒有擴展方法'SqlDataSource1_Selecting'接受'ASP.default_aspx'類型的第一個參數可以找到(是否缺少using指令或程序集引用?)

我該如何解決?

回答

1

這是因爲你定義

onselecting="SqlDataSource1_Selecting" 

,但可能在後面的代碼中有一個與正確的簽名

+0

感謝哥們我刪除了那部分,現在它的工作正常。 – user2125727

1

沒有功能的錯誤中明確規定,你沒有任何SqlDataSource1_Selecting方法(對於onselecting = 「SqlDataSource1_Selecting」 的事件處理程序)

錯誤:

ASP.default_aspx' does not contain a definition for 'SqlDataSource1_Selecting' and no extension method 'SqlDataSource1_Selecting' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)

代碼

<asp:SqlDataSource ID="SqlDataSource1" 
        runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" 
        onselecting="SqlDataSource1_Selecting" 
        SelectCommand="SELECT * FROM [student]" 
        UpdateCommand="Update student set [email protected], 
                 [email protected], 
                 [email protected], 
                 [email protected] 
            where [email protected]" > 
     </asp:SqlDataSource> 

問題的代碼

onselecting="SqlDataSource1_Selecting" there is no extension for this available 

更新時間:

你的web.config定義OLEDB連接字符串(使用OLEDB引擎)使用SQL Server OleDb提供程序連接到SQL Server通過OleDb。

然後,您的代碼將該連接字符串傳遞給SqlConnection,該SqlConnection使用SQL本機客戶端直接連接到SQL Server,並使用完全不同的連接字符串。

您應該更改Web.config以使用System.Data.SqlClient及其連接字符串格式。 (這比OleDb更有效)