0

嘿,晚上好,谁能告诉我我的代码有什么问题?我收到如下所示的“操作不可更新”错误

 Server Error in '/' Application.
 Operation must use an updateable query.

 Description: An unhandled exception occurred during the execution of the current 
  webrequest. Please review the stack trace for more information about the error 
  and where it originated in the code. 

  Exception Details: System.Data.OleDb.OleDbException: Operation must use an
 updateable query.

  Source Error: 


      Line 20:          cmd.Parameters.AddWithValue("paswords", TextBox4.Text)
      Line 21:          conn.Open()
      Line 22:          cmd.ExecuteNonQuery()
      Line 23:          End Using
      Line 24:          End Using

我的代码是

    Imports System.Web.Security
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.Configuration
    Imports System.Web.Configuration

    Partial Class Registration
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|onlineregistration.mdb"
        Dim SqlString As String = "Insert Into registration (firtsname, telephone, email, paswords) Values (?,?,?,?)"
        Using conn As New OleDbConnection(ConnString)
            Using cmd As New OleDbCommand(SqlString, conn)
                cmd.CommandType = CommandType.Text
                cmd.Parameters.AddWithValue("firtsname", TextBox1.Text)
                cmd.Parameters.AddWithValue("telephone", TextBox2.Text)
                cmd.Parameters.AddWithValue("email", TextBox3.Text)
                cmd.Parameters.AddWithValue("paswords", TextBox4.Text)
                conn.Open()
                cmd.ExecuteScalar()
            End Using
        End Using
    End Sub

End Class
4

2 回答 2

0

确保您的 ASP.NET 帐户(在大多数情况下为网络服务)对存储它的 MDB 文件/文件夹具有读/写访问权限。有时还需要 IUSR_MachineName 帐户

您也可以尝试添加Mode=ReadWrite;到您的连接字符串。

于 2013-08-15T21:49:50.050 回答
0

当 mdb 文件是只写文件或文件没有写权限时,通常会抛出“必须使用可更新查询”错误。

于 2013-08-15T21:46:24.373 回答