2011-02-11 57 views
1

我一直在做我的第一个ASP.NET Visual Studio网站,我刚开始使用数据库,我做了一个表和一个后台页面来控制内容我的桌子。更新/插入不支持数据源

本页面遵循以下规则:

- >我已经添加了SqlDataSource和配置。

- >我已经添加了一个gridview来查看我的内容并将其配置到我的SQLDataSource,在这里我添加了编辑/删除选项。

- >我添加配置到我的SWLDataSource一个DetailsView,在这里我添加新的选项(创建我的表中的新条目)

我的数据库中的id列设置主键(数据类型= INT;允许空值=未选中)

每次我试图通过这个后台页面,我得到下面的错误来更新我的数据库:

Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NotSupportedException: Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified.]
System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +1644420
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +92
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +907
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +704
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +123
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

我真的可以使用一些帮助在这里!

回答

1

errormessage说明了这一切:'更新不受数据源'SqlDataSource1'支持,除非指定了UpdateCommand。'。您必须将sql代码或存储过程的名称分配给属性UpdateCommand,以便SqlDataSource知道如何处理您的更新。

+0

我该在哪里做?对不起,我对这个网络环境很陌生... – joao

+0

没问题。毕竟,我们在这里提供帮助。按照我放在我的帖子中的链接(在“UpdateCommand”一词下):http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updatecommand.aspx。滚动到“示例”。您可以将UpdateCommand属性的sql代码放置在html页面本身(如示例中)或代码隐藏中。 –

+0

有一件事,一位朋友刚才提到我,如果我在网格视图选项中选中“启用编辑”,但是我没有该选项,只启用分页/排序/选择,这应该都可以工作......为什么是这样? – joao