有关数据库的问题

hannibalhontani 2003-10-19 08:25:24
Dim conn As OleDbConnection
conn = New OleDbConnection()
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("user.mdb")
'conn.Open()

Dim Cmd As OleDbCommand
Dim strSQL As String

strSQL = "INSERT INTO REG VALUES('" & txtID.Text & "','"
strSQL &= txtPWD.Text & "','" & txtEMail.Text & "','"
strSQL &= txtAddr.Text & "','" & txtPhone.Text & "','"
strSQL &= rbtnlstSex.SelectedItem.Value & "','" & txtBirth.Text & "')"

Cmd = New OleDbCommand(strSQL, conn)
Cmd.Connection.Open()

Try
Cmd.ExecuteNonQuery()
Catch ex As InvalidOperationException
Response.Write("数据库出错!")
conn.Close()
Exit Sub
End Try
Response.Write("恭喜,您已经注册成功了!")

conn.Close()

以上操作,给出下列错误信息,是怎么回事啊?

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

源错误:


行 153:
行 154: Try
行 155: Cmd.ExecuteNonQuery()
行 156: Catch ex As InvalidOperationException
行 157: Response.Write("数据库出错!")


源文件: D:\Program\Inetpub\wwwroot\MyWork\Reg.aspx.vb 行: 155

堆栈跟踪:


[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
MyWork.Reg.btnConfirm_Click(Object sender, EventArgs e) in D:\Program\Inetpub\wwwroot\MyWork\Reg.aspx.vb:155
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
...全文
34 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hannibalhontani 2003-10-19
  • 打赏
  • 举报
回复
那个贴子我试了没用啊。按他说的属性里没有什么安全标签啊,我用的XP。
qiuji 2003-10-19
  • 打赏
  • 举报
回复
找到数据库所在文件夹->右键->属性->安全,添加ASP.NET用户“写”的权限。
Inyoureyes 2003-10-19
  • 打赏
  • 举报
回复
那个ID是什么类型的字段?可以编辑吗?如不不可以编辑就会出错,比如主建
webdiyer 2003-10-19
  • 打赏
  • 举报
回复
需要设置权限,看这个帖子:

http://expert.csdn.net/Expert/topicview.asp?id=2259139

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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