主题:"操作必须使用一个可更新的查询"这个问题谁能解决下
我在看一本叫《ASP编程篇》的书,其中第九章"以ADO.NET操作数据库"中有这样一个例子,我从光盘上下下来使用:
[color=0000FF]<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub btClicked(ByVal Sender as Object, ByVal E as EventArgs)
Dim myConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("Athens2004.mdb")
Dim myInsertString As String = "Insert Into medals Values(7,'土耳其',1,0,0,1,'2004-8-15')"
'建立数据库连接
Dim myConnection As New OleDbConnection(myConnString)
'初始化OleDbCommand对象
Dim myCommand As New OleDbCommand(myInsertString, myConnection)
'打开数据库连接
myConnection.Open()
'执行操作
myCommand.ExecuteNonQuery()
'关闭与数据库的连接
myConnection.Close()
prompt.Text = "『土耳其』记录已经插入到数据库内。"
btDelete.Enabled = true
btInsert.Enabled = false
End Sub
Sub btDeleteData(ByVal Sender as Object, ByVal E as EventArgs)
Dim myConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("Athens2004.mdb")
Dim myInsertString As String = "Delete From medals where 国家='土耳其'"
'建立数据库连接
Dim myConnection As New OleDbConnection(myConnString)
'初始化OleDbCommand对象
Dim myCommand As New OleDbCommand(myInsertString, myConnection)
'打开数据库连接
myConnection.Open()
'执行操作
myCommand.ExecuteNonQuery()
'关闭与数据库的连接
myConnection.Close()
prompt.Text = "『土耳其』记录已经被成功删除。"
btDelete.Enabled = false
btInsert.Enabled = true
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>雅典2004</TITLE>
</HEAD>
<BODY>
<form runat="server">
<ASP:Button id="btInsert" runat="server"
Text = "插入『土耳其』的数据"
OnClick = "btClicked" >
</asp:Button>
<p>
<ASP:Button id="btDelete" runat="server"
Text = "删除『土耳其』的数据"
OnClick = "btDeleteData"
Enabled = false>
</asp:Button>
<p>
<ASP:Label id="prompt" runat="server" >
</asp:Label>
</Form>
</BODY>
</HTML>[/color]
运行后总出现这么样的页面:
[color=0000FF]“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
操作必须使用一个可更新的查询。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: 操作必须使用一个可更新的查询。
源错误:
行 20: myConnection.Open()
行 21: '执行操作
行 22: myCommand.ExecuteNonQuery()
行 23: '关闭与数据库的连接
行 24: myConnection.Close()
源文件: E:\WebSite\wwwroot\aa\OlympicExecuteNonQuery.aspx 行: 22
堆栈跟踪:
[OleDbException (0x80004005): 操作必须使用一个可更新的查询。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
ASP.OlympicExecuteNonQuery_aspx.btClicked(Object Sender, EventArgs E) in E:\WebSite\wwwroot\aa\OlympicExecuteNonQuery.aspx:22
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573 [/color]
数据库文件方面我检查过,都没问题,文件夹也开了写入属性。
那位高手能帮忙解决下
谢了
[color=0000FF]<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub btClicked(ByVal Sender as Object, ByVal E as EventArgs)
Dim myConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("Athens2004.mdb")
Dim myInsertString As String = "Insert Into medals Values(7,'土耳其',1,0,0,1,'2004-8-15')"
'建立数据库连接
Dim myConnection As New OleDbConnection(myConnString)
'初始化OleDbCommand对象
Dim myCommand As New OleDbCommand(myInsertString, myConnection)
'打开数据库连接
myConnection.Open()
'执行操作
myCommand.ExecuteNonQuery()
'关闭与数据库的连接
myConnection.Close()
prompt.Text = "『土耳其』记录已经插入到数据库内。"
btDelete.Enabled = true
btInsert.Enabled = false
End Sub
Sub btDeleteData(ByVal Sender as Object, ByVal E as EventArgs)
Dim myConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("Athens2004.mdb")
Dim myInsertString As String = "Delete From medals where 国家='土耳其'"
'建立数据库连接
Dim myConnection As New OleDbConnection(myConnString)
'初始化OleDbCommand对象
Dim myCommand As New OleDbCommand(myInsertString, myConnection)
'打开数据库连接
myConnection.Open()
'执行操作
myCommand.ExecuteNonQuery()
'关闭与数据库的连接
myConnection.Close()
prompt.Text = "『土耳其』记录已经被成功删除。"
btDelete.Enabled = false
btInsert.Enabled = true
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>雅典2004</TITLE>
</HEAD>
<BODY>
<form runat="server">
<ASP:Button id="btInsert" runat="server"
Text = "插入『土耳其』的数据"
OnClick = "btClicked" >
</asp:Button>
<p>
<ASP:Button id="btDelete" runat="server"
Text = "删除『土耳其』的数据"
OnClick = "btDeleteData"
Enabled = false>
</asp:Button>
<p>
<ASP:Label id="prompt" runat="server" >
</asp:Label>
</Form>
</BODY>
</HTML>[/color]
运行后总出现这么样的页面:
[color=0000FF]“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
操作必须使用一个可更新的查询。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: 操作必须使用一个可更新的查询。
源错误:
行 20: myConnection.Open()
行 21: '执行操作
行 22: myCommand.ExecuteNonQuery()
行 23: '关闭与数据库的连接
行 24: myConnection.Close()
源文件: E:\WebSite\wwwroot\aa\OlympicExecuteNonQuery.aspx 行: 22
堆栈跟踪:
[OleDbException (0x80004005): 操作必须使用一个可更新的查询。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
ASP.OlympicExecuteNonQuery_aspx.btClicked(Object Sender, EventArgs E) in E:\WebSite\wwwroot\aa\OlympicExecuteNonQuery.aspx:22
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573 [/color]
数据库文件方面我检查过,都没问题,文件夹也开了写入属性。
那位高手能帮忙解决下
谢了