Wrox Programmer Forums
|
BOOK: Beginning ASP.NET Databases Also see the forum ASP Databases for more general discussions of ASP database issues not directly related to these books.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2004, 10:12 AM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default INSERTing REcords

I am working from the Beginning ASP.NET DB book. I copied the code and changed the db path. When I run the code I receive the following error message: Operation must use an updateable query..

My code is:
<%@ Page Language="VB" Debug="true" %>
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.OleDb" %>

<html>
  <head>
    <title>Validating a Field</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">
      <table id="Table1"
             style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px"
             cellSpacing="0" cellPadding="0" width="300" border="0">
        <tr>
          <td style="WIDTH: 115px">
            <asp:Label id="Label1" runat="server">CategoryName</asp:Label>
          </td>
          <td>
            <asp:TextBox id="txtCategoryName" runat="server" width="193" />
          </td>
        </tr>
        <tr>
          <td style="WIDTH: 115px">
            <asp:Label id="Label2" runat="server">Description</asp:Label>
          </td>
          <td>
            <asp:TextBox id="txtDescription" runat="server" width="193" />
          </td>
        </tr>
        <tr>
          <td style="WIDTH: 115px" colSpan="2">
            <asp:Button id="btnInsert" runat="server"
                 OnClick="btnInsert_Click" width="298" text="INSERT!" />
          </td>
        </tr>
      </table>
      <asp:RequiredFieldValidator id="rfvCategoryName" runat="server"
          style="Z-INDEX: 102; LEFT: 316px; POSITION: absolute; TOP: 14px"
          ErrorMessage="Please insert the new category name"
          ControlToValidate="txtCategoryName" />
    </form>
  </body>
</html>

<script language="VB" runat="server">
Dim objConnection As OleDbConnection

Sub Page_Load(Source as Object, E as EventArgs)
    Dim strDBPath As String

    strDBPath = Server.MapPath("..\Database\Northwind.mdb")
    objConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OleDb.4.0;DATA Source=" & strDBPath & ";" )

End Sub

Sub btnInsert_Click(Sender As Object, E As EventArgs)
  If Page.IsValid Then
    Dim strSQL As String = "INSERT INTO Categories " & _
                           "(CategoryName, Description) VALUES (?, ?)"

    Dim dbComm As New OleDbCommand(strSQL, objConnection)
    dbComm.Parameters.Add("CategoryName", OleDbType.VarChar, 32, "CategoryName")
    dbComm.Parameters.Add("Description", OleDbType.VarChar, 128, "Description")

    dbComm.Parameters("CategoryName").Value = txtCategoryName.Text
    dbComm.Parameters("Description").Value = txtDescription.Text

    Try
      objConnection.Open()
      dbComm.ExecuteNonQuery()
    Catch ex As Exception
      Response.Write(ex.Message)
      Response.End
    Finally
      If objConnection.State = ConnectionState.Open Then
        objConnection.Close()
      End If
    End Try

    Response.Write("A new record has been added")
    Response.End
  End If
End Sub
</script>
 
Old January 12th, 2004, 12:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You need to find the northwind database and right click on it and click:

properties | sharing and security

then add the aspnet user account to the list and give it 'write' permissions so that it can update the file.

 
Old January 12th, 2004, 06:03 PM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I made the change you stated and I still am receiving the error message.

 
Old January 13th, 2004, 06:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You need to do that permissions thing on the folder that contains the northwind database, not just the database file itself. This is because of Access's use of lock files (the .ldb file).

http://www.aspfaq.com/show.asp?id=2062 for more detail.
 
Old January 13th, 2004, 12:40 PM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default

The permissions was the problem, thank you.
All is working fine now. :)

 
Old January 30th, 2004, 05:40 PM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Problem has been resolved.
TY






Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate records while inserting the data ebindia0041 .NET Framework 1.x 0 May 23rd, 2007 07:15 PM
Inserting Records Question? ersp ADO.NET 1 May 12th, 2004 09:55 AM
Inserting Returned Records [email protected] SQL Language 2 November 4th, 2003 01:05 PM
Inserting records into a databae aadz5 ASP.NET 1.0 and 1.1 Basics 1 October 19th, 2003 10:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.