ado.net 更新access 数据库的问题

晓疯馋曰 2002-07-24 08:02:02
用ado.net 更新access数据库总报错。
语句是没错的,
请问怎样设置数据库的权限?
...全文
51 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
晓疯馋曰 2002-07-29
  • 打赏
  • 举报
回复
点Insert 出现的错误信息:

“/xnyy”应用程序中的服务器错误。
--------------------------------------------------------------------------------

操作必须使用一个可更新的查询。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.OleDb.OleDbException: 操作必须使用一个可更新的查询。

源错误:


行 35: cbInsert.CommandText = sInsertSQL
行 36: cbInsert.CommandType = CommandType.Text
行 37: cbInsert.ExecuteNonQuery()
行 38:
行 39: cnNorthwind.Close()


源文件: c:\inetpub\wwwroot\xnyy\2.aspx.vb 行: 37

堆栈跟踪:


[OleDbException (0x80004005): 操作必须使用一个可更新的查询。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +154
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +54
xnyy._2.Insert_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\xnyy\2.aspx.vb:37
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1263




--------------------------------------------------------------------------------
版本信息: Microsoft .NET 框架版本:1.0.3705.0; ASP.NET 版本:1.0.3705.0
晓疯馋曰 2002-07-29
  • 打赏
  • 举报
回复
不好意思,还是不行,我帖出来再看看:
2.aspx

<%@ Page CodeBehind="2.aspx.vb" Language="vb" AutoEventWireup="false" Inherits="xnyy._2" %>
<HTML>
<HEAD>
</HEAD>
<body>
<form runat="server" ID="Form1">
<h3>
<asp:Button id="Insert" runat="server" Text="Insert"></asp:Button>
<asp:Button id="Update" runat="server" Text="Update"></asp:Button></h3>
</form>
</body>
</HTML>



2.aspx.vb

Public Class _2
Inherits System.Web.UI.Page
Protected WithEvents Insert As System.Web.UI.WebControls.Button
Protected WithEvents Update As System.Web.UI.WebControls.Button

#Region " Web 窗体设计器生成的代码 "

'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Private Sub Insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Insert.Click
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\Microsoft Office\Office10\Samples\northwind.mdb"

Dim cnNorthwind As New OleDb.OleDbConnection(sConnectionString)
cnNorthwind.Open()

Dim sInsertSQL As String = "insert into 运货商 (公司名称,电话) values ('MSOffice','6108')"
Dim cbInsert As New OleDb.OleDbCommand()

cbInsert.Connection = cnNorthwind
cbInsert.CommandText = sInsertSQL
cbInsert.CommandType = CommandType.Text
cbInsert.ExecuteNonQuery()

cnNorthwind.Close()

End Sub



Private Sub Update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Update.Click
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\Microsoft Office\Office10\Samples\northwind.mdb"

Dim cnNorthwind As New OleDb.OleDbConnection(sConnectionString)
cnNorthwind.Open()

Dim sUpdateSQL As String = "update 运货商 set 公司名称='RuiDTAMS',电话='61086108' where 运货商ID=4"
Dim cbUpdate As New OleDb.OleDbCommand()

cbUpdate.Connection = cnNorthwind
cbUpdate.CommandText = sUpdateSQL
cbUpdate.CommandType = CommandType.Text
cbUpdate.ExecuteNonQuery()

cnNorthwind.Close()
End Sub



End Class


谢谢!
ruidong 2002-07-26
  • 打赏
  • 举报
回复
感谢您使用微软产品。



我贴出我的代码供您参考:



Private Sub Insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Insert.Click
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=I:\Program Files\Microsoft Office\Office10\Samples\northwind.mdb"

Dim cnNorthwind As New OleDbConnection(sConnectionString)
cnNorthwind.Open()

Dim sInsertSQL As String = "insert into 运货商 (公司名称,电话) values ('MSOffice','6108')"
Dim cbInsert As New OleDbCommand()

cbInsert.Connection = cnNorthwind
cbInsert.CommandText = sInsertSQL
cbInsert.CommandType = CommandType.Text
cbInsert.ExecuteNonQuery()

cnNorthwind.Close()

End Sub



Private Sub Update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Update.Click
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=I:\Program Files\Microsoft Office\Office10\Samples\northwind.mdb"

Dim cnNorthwind As New OleDbConnection(sConnectionString)
cnNorthwind.Open()

Dim sUpdateSQL As String = "update 运货商 set 公司名称='RuiDTAMS',电话='61086108' where 运货商ID=4"
Dim cbUpdate As New OleDbCommand()

cbUpdate.Connection = cnNorthwind
cbUpdate.CommandText = sUpdateSQL
cbUpdate.CommandType = CommandType.Text
cbUpdate.ExecuteNonQuery()

cnNorthwind.Close()
End Sub


该代码新填,更新Access中的例子数据库northwind.mdb的运货商表。您可参考northwind.mdb数据库。




希望这些讯息对您有帮助。



- 微软全球技术中心 DTA技术支持



本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款 (http://www.csdn.net/microsoft/terms.shtm)。
comy 2002-07-25
  • 打赏
  • 举报
回复
错误贴出来看看
晓疯馋曰 2002-07-25
  • 打赏
  • 举报
回复
就是不能更新,用oledbcommand对象
insert into 报语法错
update 报没有可更新的查询
相同的语句我在Access里通过的
comy 2002-07-24
  • 打赏
  • 举报
回复
报什么错啊?

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧