Connecting Tech Pros Worldwide Help | Site Map

Operation must use an updateable query ..

Jim in Arizona
Guest
 
Posts: n/a
#1: Dec 12 '05
I've been using an example out of a book to be able to edit the rows in a
database. I am getting the following error:

================================================== ======
================================================== ======

Server Error in '/' Application.
--------------------------------------------------------------------------------
Operation must use an updateable query.
Description: An unhandled exception occurred during the execution of the
current web request. 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 74:
Line 75: objConnection.Open()
Line 76: adapter.Update(ds, "TMaster")
Line 77:
Line 78: objConnection.Close()

Source File: E:\hhsinternal\tests\editing\editing.aspx.vb Line: 76

Stack Trace:

[OleDbException (0x80004005): Operation must use an updateable query.]
System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
+1303846
System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +46
System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping) +1750
System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable dataTable,
DataTableMapping tableMapping) +40
System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
+180
tests_editing_editing.Update(Int32 PK, String FirstName) in
E:\hhsinternal\tests\editing\editing.aspx.vb:76
tests_editing_editing.UpdateRecord(Object Sender,
DataGridCommandEventArgs E) in
E:\hhsinternal\tests\editing\editing.aspx.vb:39
System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs
e) +105
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs
e) +679
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +115
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +134
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +180
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50215.44; ASP.NET
Version:2.0.50215.44

================================================== ======
================================================== ======

I can pretty much follow the code, but I don't understand what updateably
query it is referring to.

Line 75: adapter.Update(ds, "TMaster")

I have a single MS Access 2003 DB with a single table TMaster and Four
columns (PK, FirstName, LastName, EmpID). I am only pulling the data for the
PK and FirstName for my testing purposes (See SQL Statement in code).

This is my code (editing.aspx.vb), the first Imports statement starts as
Line 1. TIA, Jim

Imports System.Data
Imports System.Data.OleDb

Partial Class tests_editing_editing
Inherits System.Web.UI.Page
Public Sub EditRecord(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)
employees.EditItemIndex = E.Item.ItemIndex
LoadGrid()
End Sub
Public Sub CancelRecord(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)
employees.EditItemIndex = -1
LoadGrid()
End Sub

Public Sub UpdateRecord(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)
Dim objConnection As OleDbConnection
Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=e:\hhsinternal\tests\editing\editing.mdb"

If objConnection Is Nothing Then
objConnection = New OleDbConnection(strConnection)
End If

If objConnection.State = ConnectionState.Closed Then
objConnection.Open()
End If
Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"

Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
Dim ds As New DataSet()
adapter.Fill(ds, "TMaster")
objConnection.Close()

'Retrieve the field values in the edited row
Dim PK As Int32 = Convert.ToInt32(E.Item.Cells(0).Text)
Dim FirstNameTextBox As TextBox = CType(E.Item.Cells(1).Controls(0),
TextBox)
Dim FirstName As String = Convert.ToString(FirstNameTextBox.Text)

employees.EditItemIndex = -1
Update(PK, FirstName)

employees.DataSource = ds.tables("TMaster")
employees.DataBind()

End Sub

Public Sub Update(ByVal PK As Int32, ByVal FirstName As String)
Dim objConnection As OleDbConnection
Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=e:\hhsinternal\tests\editing\editing.mdb"

If objConnection Is Nothing Then
objConnection = New OleDbConnection(strConnection)
End If

If objConnection.State = ConnectionState.Closed Then
objConnection.Open()
End If
Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"

Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
Dim ds As New DataSet()
adapter.Fill(ds, "TMaster")
objConnection.Close()


Dim tbl As DataTable = ds.Tables("TMaster")
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("PK") _
}
Dim row As DataRow = tbl.Rows.Find(PK)
row.Item("FirstName") = FirstName

Dim cb As New OleDbCommandBuilder(adapter)

objConnection.Open()
adapter.Update(ds, "TMaster")

objConnection.Close()
End Sub

Private Sub LoadGrid()
Dim objConnection As OleDbConnection
Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=e:\hhsinternal\tests\editing\editing.mdb"

If objConnection Is Nothing Then
objConnection = New OleDbConnection(strConnection)
End If

If objConnection.State = ConnectionState.Closed Then
objConnection.Open()
End If

Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"

Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
Dim ds As New DataSet()
adapter.Fill(ds, "TMaster")
objConnection.Close()

With employees
.DataSource = ds.Tables("TMaster")
.DataBind()
End With

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
LoadGrid()
End If
End Sub
End Class

===========================================
===========================================
Below is the editing.aspx code if needed ..
===========================================
===========================================

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="editing.aspx.vb"
Inherits="tests_editing_editing" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataGrid ID="employees" runat="server" CellPadding="5"
AutoGenerateColumns="false" OnEditCommand="EditRecord"
OnCancelCommand="CancelRecord"
OnUpdateCommand="UpdateRecord">
<Columns>
<asp:BoundColumn DataField="PK" ReadOnly="true" Visible="false" />
<asp:BoundColumn DataField="FirstName" HeaderText="First Name"
ReadOnly="False" />
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Save"
CancelText="Cancel" EditText="Edit" />
</Columns>
</asp:DataGrid>
</div>
</form>
</body>
</html>





Marina
Guest
 
Posts: n/a
#2: Dec 12 '05

re: Operation must use an updateable query ..


You didn't define an update query for the adapter to use. It doesn't know
how to do the update on its own.

You either have to supply the update command, or you have to use an
OleDBCommandBuilder object. If can do some research on both these techniques
for more information.

"Jim in Arizona" <tiltowait@hotmail.com> wrote in message
news:expPkN2$FHA.1312@TK2MSFTNGP09.phx.gbl...[color=blue]
> I've been using an example out of a book to be able to edit the rows in a
> database. I am getting the following error:
>
> ================================================== ======
> ================================================== ======
>
> Server Error in '/' Application.
> --------------------------------------------------------------------------------
> Operation must use an updateable query.
> Description: An unhandled exception occurred during the execution of the
> current web request. 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 74:
> Line 75: objConnection.Open()
> Line 76: adapter.Update(ds, "TMaster")
> Line 77:
> Line 78: objConnection.Close()
>
> Source File: E:\hhsinternal\tests\editing\editing.aspx.vb Line: 76
>
> Stack Trace:
>
> [OleDbException (0x80004005): Operation must use an updateable query.]
>
> System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs
> rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
> +1303846
> System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs
> rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +46
> System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
> DataTableMapping tableMapping) +1750
> System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable
> dataTable, DataTableMapping tableMapping) +40
> System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
> srcTable) +180
> tests_editing_editing.Update(Int32 PK, String FirstName) in
> E:\hhsinternal\tests\editing\editing.aspx.vb:76
> tests_editing_editing.UpdateRecord(Object Sender,
> DataGridCommandEventArgs E) in
> E:\hhsinternal\tests\editing\editing.aspx.vb:39
>
> System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs
> e) +105
> System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source,
> EventArgs e) +679
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
> +35
> System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
> EventArgs e) +117
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
> +35
> System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +115
> System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
> eventArgument) +134
>
> System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
> eventArgument) +7
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> sourceControl, String eventArgument) +11
> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +180
> System.Web.UI.Page.ProcessRequestMain(Boolean
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670
>
> --------------------------------------------------------------------------------
> Version Information: Microsoft .NET Framework Version:2.0.50215.44;
> ASP.NET Version:2.0.50215.44
>
> ================================================== ======
> ================================================== ======
>
> I can pretty much follow the code, but I don't understand what updateably
> query it is referring to.
>
> Line 75: adapter.Update(ds, "TMaster")
>
> I have a single MS Access 2003 DB with a single table TMaster and Four
> columns (PK, FirstName, LastName, EmpID). I am only pulling the data for
> the PK and FirstName for my testing purposes (See SQL Statement in code).
>
> This is my code (editing.aspx.vb), the first Imports statement starts as
> Line 1. TIA, Jim
>
> Imports System.Data
> Imports System.Data.OleDb
>
> Partial Class tests_editing_editing
> Inherits System.Web.UI.Page
> Public Sub EditRecord(ByVal Sender As Object, ByVal E As
> DataGridCommandEventArgs)
> employees.EditItemIndex = E.Item.ItemIndex
> LoadGrid()
> End Sub
> Public Sub CancelRecord(ByVal Sender As Object, ByVal E As
> DataGridCommandEventArgs)
> employees.EditItemIndex = -1
> LoadGrid()
> End Sub
>
> Public Sub UpdateRecord(ByVal Sender As Object, ByVal E As
> DataGridCommandEventArgs)
> Dim objConnection As OleDbConnection
> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=e:\hhsinternal\tests\editing\editing.mdb"
>
> If objConnection Is Nothing Then
> objConnection = New OleDbConnection(strConnection)
> End If
>
> If objConnection.State = ConnectionState.Closed Then
> objConnection.Open()
> End If
> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>
> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
> Dim ds As New DataSet()
> adapter.Fill(ds, "TMaster")
> objConnection.Close()
>
> 'Retrieve the field values in the edited row
> Dim PK As Int32 = Convert.ToInt32(E.Item.Cells(0).Text)
> Dim FirstNameTextBox As TextBox =
> CType(E.Item.Cells(1).Controls(0), TextBox)
> Dim FirstName As String = Convert.ToString(FirstNameTextBox.Text)
>
> employees.EditItemIndex = -1
> Update(PK, FirstName)
>
> employees.DataSource = ds.tables("TMaster")
> employees.DataBind()
>
> End Sub
>
> Public Sub Update(ByVal PK As Int32, ByVal FirstName As String)
> Dim objConnection As OleDbConnection
> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=e:\hhsinternal\tests\editing\editing.mdb"
>
> If objConnection Is Nothing Then
> objConnection = New OleDbConnection(strConnection)
> End If
>
> If objConnection.State = ConnectionState.Closed Then
> objConnection.Open()
> End If
> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>
> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
> Dim ds As New DataSet()
> adapter.Fill(ds, "TMaster")
> objConnection.Close()
>
>
> Dim tbl As DataTable = ds.Tables("TMaster")
> tbl.PrimaryKey = New DataColumn() _
> { _
> tbl.Columns("PK") _
> }
> Dim row As DataRow = tbl.Rows.Find(PK)
> row.Item("FirstName") = FirstName
>
> Dim cb As New OleDbCommandBuilder(adapter)
>
> objConnection.Open()
> adapter.Update(ds, "TMaster")
>
> objConnection.Close()
> End Sub
>
> Private Sub LoadGrid()
> Dim objConnection As OleDbConnection
> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=e:\hhsinternal\tests\editing\editing.mdb"
>
> If objConnection Is Nothing Then
> objConnection = New OleDbConnection(strConnection)
> End If
>
> If objConnection.State = ConnectionState.Closed Then
> objConnection.Open()
> End If
>
> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>
> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
> Dim ds As New DataSet()
> adapter.Fill(ds, "TMaster")
> objConnection.Close()
>
> With employees
> .DataSource = ds.Tables("TMaster")
> .DataBind()
> End With
>
> End Sub
>
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Me.Load
> If Not Page.IsPostBack Then
> LoadGrid()
> End If
> End Sub
> End Class
>
> ===========================================
> ===========================================
> Below is the editing.aspx code if needed ..
> ===========================================
> ===========================================
>
> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="editing.aspx.vb"
> Inherits="tests_editing_editing" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:DataGrid ID="employees" runat="server" CellPadding="5"
> AutoGenerateColumns="false" OnEditCommand="EditRecord"
> OnCancelCommand="CancelRecord"
> OnUpdateCommand="UpdateRecord">
> <Columns>
> <asp:BoundColumn DataField="PK" ReadOnly="true" Visible="false" />
> <asp:BoundColumn DataField="FirstName" HeaderText="First Name"
> ReadOnly="False" />
> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Save"
> CancelText="Cancel" EditText="Edit" />
> </Columns>
> </asp:DataGrid>
> </div>
> </form>
> </body>
> </html>
>
>
>
>
>[/color]


Juan T. Llibre
Guest
 
Posts: n/a
#3: Dec 12 '05

re: Operation must use an updateable query ..


The most common problem asociated with the
"Operation must use an updateable query" error message is that the
account you are using doesn't have read/write permissions to the
directory and/or Access database file which you are trying to modify.





Juan T. Llibre
ASP.NET MVP
============
"Jim in Arizona" <tiltowait@hotmail.com> wrote in message
news:expPkN2$FHA.1312@TK2MSFTNGP09.phx.gbl...[color=blue]
> I've been using an example out of a book to be able to edit the rows in a database. I am getting
> the following error:
>
> ================================================== ======
> ================================================== ======
>
> Server Error in '/' Application.
> --------------------------------------------------------------------------------
> Operation must use an updateable query.
> Description: An unhandled exception occurred during the execution of the current web request.
> 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 74:
> Line 75: objConnection.Open()
> Line 76: adapter.Update(ds, "TMaster")
> Line 77:
> Line 78: objConnection.Close()
>
> Source File: E:\hhsinternal\tests\editing\editing.aspx.vb Line: 76
>
> Stack Trace:
>
> [OleDbException (0x80004005): Operation must use an updateable query.]
> System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs rowUpdatedEvent,
> BatchCommandInfo[] batchCommands, Int32 commandCount) +1303846
> System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs rowUpdatedEvent,
> BatchCommandInfo[] batchCommands, Int32 commandCount) +46
> System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) +1750
> System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable dataTable, DataTableMapping
> tableMapping) +40
> System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) +180
> tests_editing_editing.Update(Int32 PK, String FirstName) in
> E:\hhsinternal\tests\editing\editing.aspx.vb:76
> tests_editing_editing.UpdateRecord(Object Sender, DataGridCommandEventArgs E) in
> E:\hhsinternal\tests\editing\editing.aspx.vb:39
> System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs e) +105
> System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs e) +679
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
> System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source, EventArgs e) +117
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
> System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +115
> System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String eventArgument) +134
>
> System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
> eventArgument) +7
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
> +11
> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +180
> System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean
> includeStagesAfterAsyncPoint) +5670
>
> --------------------------------------------------------------------------------
> Version Information: Microsoft .NET Framework Version:2.0.50215.44; ASP.NET Version:2.0.50215.44
>
> ================================================== ======
> ================================================== ======
>
> I can pretty much follow the code, but I don't understand what updateably query it is referring
> to.
>
> Line 75: adapter.Update(ds, "TMaster")
>
> I have a single MS Access 2003 DB with a single table TMaster and Four columns (PK, FirstName,
> LastName, EmpID). I am only pulling the data for the PK and FirstName for my testing purposes (See
> SQL Statement in code).
>
> This is my code (editing.aspx.vb), the first Imports statement starts as Line 1. TIA, Jim
>
> Imports System.Data
> Imports System.Data.OleDb
>
> Partial Class tests_editing_editing
> Inherits System.Web.UI.Page
> Public Sub EditRecord(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
> employees.EditItemIndex = E.Item.ItemIndex
> LoadGrid()
> End Sub
> Public Sub CancelRecord(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
> employees.EditItemIndex = -1
> LoadGrid()
> End Sub
>
> Public Sub UpdateRecord(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
> Dim objConnection As OleDbConnection
> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=e:\hhsinternal\tests\editing\editing.mdb"
>
> If objConnection Is Nothing Then
> objConnection = New OleDbConnection(strConnection)
> End If
>
> If objConnection.State = ConnectionState.Closed Then
> objConnection.Open()
> End If
> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>
> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
> Dim ds As New DataSet()
> adapter.Fill(ds, "TMaster")
> objConnection.Close()
>
> 'Retrieve the field values in the edited row
> Dim PK As Int32 = Convert.ToInt32(E.Item.Cells(0).Text)
> Dim FirstNameTextBox As TextBox = CType(E.Item.Cells(1).Controls(0), TextBox)
> Dim FirstName As String = Convert.ToString(FirstNameTextBox.Text)
>
> employees.EditItemIndex = -1
> Update(PK, FirstName)
>
> employees.DataSource = ds.tables("TMaster")
> employees.DataBind()
>
> End Sub
>
> Public Sub Update(ByVal PK As Int32, ByVal FirstName As String)
> Dim objConnection As OleDbConnection
> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=e:\hhsinternal\tests\editing\editing.mdb"
>
> If objConnection Is Nothing Then
> objConnection = New OleDbConnection(strConnection)
> End If
>
> If objConnection.State = ConnectionState.Closed Then
> objConnection.Open()
> End If
> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>
> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
> Dim ds As New DataSet()
> adapter.Fill(ds, "TMaster")
> objConnection.Close()
>
>
> Dim tbl As DataTable = ds.Tables("TMaster")
> tbl.PrimaryKey = New DataColumn() _
> { _
> tbl.Columns("PK") _
> }
> Dim row As DataRow = tbl.Rows.Find(PK)
> row.Item("FirstName") = FirstName
>
> Dim cb As New OleDbCommandBuilder(adapter)
>
> objConnection.Open()
> adapter.Update(ds, "TMaster")
>
> objConnection.Close()
> End Sub
>
> Private Sub LoadGrid()
> Dim objConnection As OleDbConnection
> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=e:\hhsinternal\tests\editing\editing.mdb"
>
> If objConnection Is Nothing Then
> objConnection = New OleDbConnection(strConnection)
> End If
>
> If objConnection.State = ConnectionState.Closed Then
> objConnection.Open()
> End If
>
> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>
> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
> Dim ds As New DataSet()
> adapter.Fill(ds, "TMaster")
> objConnection.Close()
>
> With employees
> .DataSource = ds.Tables("TMaster")
> .DataBind()
> End With
>
> End Sub
>
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
> If Not Page.IsPostBack Then
> LoadGrid()
> End If
> End Sub
> End Class
>
> ===========================================
> ===========================================
> Below is the editing.aspx code if needed ..
> ===========================================
> ===========================================
>
> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="editing.aspx.vb"
> Inherits="tests_editing_editing" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:DataGrid ID="employees" runat="server" CellPadding="5"
> AutoGenerateColumns="false" OnEditCommand="EditRecord" OnCancelCommand="CancelRecord"
> OnUpdateCommand="UpdateRecord">
> <Columns>
> <asp:BoundColumn DataField="PK" ReadOnly="true" Visible="false" />
> <asp:BoundColumn DataField="FirstName" HeaderText="First Name" ReadOnly="False" />
> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Save" CancelText="Cancel"
> EditText="Edit" />
> </Columns>
> </asp:DataGrid>
> </div>
> </form>
> </body>
> </html>
>
>
>
>
>[/color]


Patrick.O.Ige
Guest
 
Posts: n/a
#4: Dec 13 '05

re: Operation must use an updateable query ..


Jim i blogged about that error at:-
http://spaces.msn.com/members/naijacoder/
Look for the Error and read on.
Hope that helps
PAtrick


"Jim in Arizona" <tiltowait@hotmail.com> wrote in message
news:expPkN2$FHA.1312@TK2MSFTNGP09.phx.gbl...[color=blue]
> I've been using an example out of a book to be able to edit the rows in a
> database. I am getting the following error:
>
> ================================================== ======
> ================================================== ======
>
> Server Error in '/' Application.
> --------------------------------------------------------------------------[/color]
------[color=blue]
> Operation must use an updateable query.
> Description: An unhandled exception occurred during the execution of the
> current web request. 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 74:
> Line 75: objConnection.Open()
> Line 76: adapter.Update(ds, "TMaster")
> Line 77:
> Line 78: objConnection.Close()
>
> Source File: E:\hhsinternal\tests\editing\editing.aspx.vb Line: 76
>
> Stack Trace:
>
> [OleDbException (0x80004005): Operation must use an updateable query.]
>[/color]
System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs[color=blue]
> rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
> +1303846
> System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs
> rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +46
> System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
> DataTableMapping tableMapping) +1750
> System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable[/color]
dataTable,[color=blue]
> DataTableMapping tableMapping) +40
> System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String[/color]
srcTable)[color=blue]
> +180
> tests_editing_editing.Update(Int32 PK, String FirstName) in
> E:\hhsinternal\tests\editing\editing.aspx.vb:76
> tests_editing_editing.UpdateRecord(Object Sender,
> DataGridCommandEventArgs E) in
> E:\hhsinternal\tests\editing\editing.aspx.vb:39
>[/color]
System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs[color=blue]
> e) +105
> System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source,[/color]
EventArgs[color=blue]
> e) +679
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)[/color]
+35[color=blue]
> System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
> EventArgs e) +117
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)[/color]
+35[color=blue]
> System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +115
> System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
> eventArgument) +134
>[/color]
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.Rai
sePostBackEvent(String[color=blue]
> eventArgument) +7
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> sourceControl, String eventArgument) +11
> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)[/color]
+180[color=blue]
> System.Web.UI.Page.ProcessRequestMain(Boolean
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670
>
> --------------------------------------------------------------------------[/color]
------[color=blue]
> Version Information: Microsoft .NET Framework Version:2.0.50215.44;[/color]
ASP.NET[color=blue]
> Version:2.0.50215.44
>
> ================================================== ======
> ================================================== ======
>
> I can pretty much follow the code, but I don't understand what updateably
> query it is referring to.
>
> Line 75: adapter.Update(ds, "TMaster")
>
> I have a single MS Access 2003 DB with a single table TMaster and Four
> columns (PK, FirstName, LastName, EmpID). I am only pulling the data for[/color]
the[color=blue]
> PK and FirstName for my testing purposes (See SQL Statement in code).
>
> This is my code (editing.aspx.vb), the first Imports statement starts as
> Line 1. TIA, Jim
>
> Imports System.Data
> Imports System.Data.OleDb
>
> Partial Class tests_editing_editing
> Inherits System.Web.UI.Page
> Public Sub EditRecord(ByVal Sender As Object, ByVal E As
> DataGridCommandEventArgs)
> employees.EditItemIndex = E.Item.ItemIndex
> LoadGrid()
> End Sub
> Public Sub CancelRecord(ByVal Sender As Object, ByVal E As
> DataGridCommandEventArgs)
> employees.EditItemIndex = -1
> LoadGrid()
> End Sub
>
> Public Sub UpdateRecord(ByVal Sender As Object, ByVal E As
> DataGridCommandEventArgs)
> Dim objConnection As OleDbConnection
> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=e:\hhsinternal\tests\editing\editing.mdb"
>
> If objConnection Is Nothing Then
> objConnection = New OleDbConnection(strConnection)
> End If
>
> If objConnection.State = ConnectionState.Closed Then
> objConnection.Open()
> End If
> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>
> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
> Dim ds As New DataSet()
> adapter.Fill(ds, "TMaster")
> objConnection.Close()
>
> 'Retrieve the field values in the edited row
> Dim PK As Int32 = Convert.ToInt32(E.Item.Cells(0).Text)
> Dim FirstNameTextBox As TextBox =[/color]
CType(E.Item.Cells(1).Controls(0),[color=blue]
> TextBox)
> Dim FirstName As String = Convert.ToString(FirstNameTextBox.Text)
>
> employees.EditItemIndex = -1
> Update(PK, FirstName)
>
> employees.DataSource = ds.tables("TMaster")
> employees.DataBind()
>
> End Sub
>
> Public Sub Update(ByVal PK As Int32, ByVal FirstName As String)
> Dim objConnection As OleDbConnection
> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=e:\hhsinternal\tests\editing\editing.mdb"
>
> If objConnection Is Nothing Then
> objConnection = New OleDbConnection(strConnection)
> End If
>
> If objConnection.State = ConnectionState.Closed Then
> objConnection.Open()
> End If
> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>
> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
> Dim ds As New DataSet()
> adapter.Fill(ds, "TMaster")
> objConnection.Close()
>
>
> Dim tbl As DataTable = ds.Tables("TMaster")
> tbl.PrimaryKey = New DataColumn() _
> { _
> tbl.Columns("PK") _
> }
> Dim row As DataRow = tbl.Rows.Find(PK)
> row.Item("FirstName") = FirstName
>
> Dim cb As New OleDbCommandBuilder(adapter)
>
> objConnection.Open()
> adapter.Update(ds, "TMaster")
>
> objConnection.Close()
> End Sub
>
> Private Sub LoadGrid()
> Dim objConnection As OleDbConnection
> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=e:\hhsinternal\tests\editing\editing.mdb"
>
> If objConnection Is Nothing Then
> objConnection = New OleDbConnection(strConnection)
> End If
>
> If objConnection.State = ConnectionState.Closed Then
> objConnection.Open()
> End If
>
> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>
> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
> Dim ds As New DataSet()
> adapter.Fill(ds, "TMaster")
> objConnection.Close()
>
> With employees
> .DataSource = ds.Tables("TMaster")
> .DataBind()
> End With
>
> End Sub
>
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Me.Load
> If Not Page.IsPostBack Then
> LoadGrid()
> End If
> End Sub
> End Class
>
> ===========================================
> ===========================================
> Below is the editing.aspx code if needed ..
> ===========================================
> ===========================================
>
> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="editing.aspx.vb"
> Inherits="tests_editing_editing" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:DataGrid ID="employees" runat="server" CellPadding="5"
> AutoGenerateColumns="false" OnEditCommand="EditRecord"
> OnCancelCommand="CancelRecord"
> OnUpdateCommand="UpdateRecord">
> <Columns>
> <asp:BoundColumn DataField="PK" ReadOnly="true" Visible="false" />
> <asp:BoundColumn DataField="FirstName" HeaderText="First Name"
> ReadOnly="False" />
> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Save"
> CancelText="Cancel" EditText="Edit" />
> </Columns>
> </asp:DataGrid>
> </div>
> </form>
> </body>
> </html>
>
>
>
>
>[/color]


Jim in Arizona
Guest
 
Posts: n/a
#5: Dec 13 '05

re: Operation must use an updateable query ..



"Patrick.O.Ige" <naijacoder@hotmail.com> wrote in message
news:%233g2Ax6$FHA.3928@tk2msftngp13.phx.gbl...[color=blue]
> Jim i blogged about that error at:-
> http://spaces.msn.com/members/naijacoder/
> Look for the Error and read on.
> Hope that helps
> PAtrick
>[/color]

I remember having such issues when I was working with classic ASP and in
most cases it was security permissions on the access DB. Because of that
prior experience, I made sure to check the permissions before I posted and
security permissions are full control for all auth users on our network, and
I'm an admin so have full control anyway. I double check again this morning
to make sure and I still get the same error. I'm at a loss.[color=blue]
> "Jim in Arizona" <tiltowait@hotmail.com> wrote in message
> news:expPkN2$FHA.1312@TK2MSFTNGP09.phx.gbl...[color=green]
>> I've been using an example out of a book to be able to edit the rows in a
>> database. I am getting the following error:
>>
>> ================================================== ======
>> ================================================== ======
>>
>> Server Error in '/' Application.
>> --------------------------------------------------------------------------[/color]
> ------[color=green]
>> Operation must use an updateable query.
>> Description: An unhandled exception occurred during the execution of the
>> current web request. 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 74:
>> Line 75: objConnection.Open()
>> Line 76: adapter.Update(ds, "TMaster")
>> Line 77:
>> Line 78: objConnection.Close()
>>
>> Source File: E:\hhsinternal\tests\editing\editing.aspx.vb Line: 76
>>
>> Stack Trace:
>>
>> [OleDbException (0x80004005): Operation must use an updateable query.]
>>[/color]
> System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs[color=green]
>> rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
>> +1303846
>> System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs
>> rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
>> +46
>> System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
>> DataTableMapping tableMapping) +1750
>> System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable[/color]
> dataTable,[color=green]
>> DataTableMapping tableMapping) +40
>> System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String[/color]
> srcTable)[color=green]
>> +180
>> tests_editing_editing.Update(Int32 PK, String FirstName) in
>> E:\hhsinternal\tests\editing\editing.aspx.vb:76
>> tests_editing_editing.UpdateRecord(Object Sender,
>> DataGridCommandEventArgs E) in
>> E:\hhsinternal\tests\editing\editing.aspx.vb:39
>>[/color]
> System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs[color=green]
>> e) +105
>> System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source,[/color]
> EventArgs[color=green]
>> e) +679
>> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)[/color]
> +35[color=green]
>> System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
>> EventArgs e) +117
>> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)[/color]
> +35[color=green]
>> System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)
>> +115
>> System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
>> eventArgument) +134
>>[/color]
> System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.Rai
> sePostBackEvent(String[color=green]
>> eventArgument) +7
>> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
>> sourceControl, String eventArgument) +11
>> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)[/color]
> +180[color=green]
>> System.Web.UI.Page.ProcessRequestMain(Boolean
>> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>> +5670
>>
>> --------------------------------------------------------------------------[/color]
> ------[color=green]
>> Version Information: Microsoft .NET Framework Version:2.0.50215.44;[/color]
> ASP.NET[color=green]
>> Version:2.0.50215.44
>>
>> ================================================== ======
>> ================================================== ======
>>
>> I can pretty much follow the code, but I don't understand what updateably
>> query it is referring to.
>>
>> Line 75: adapter.Update(ds, "TMaster")
>>
>> I have a single MS Access 2003 DB with a single table TMaster and Four
>> columns (PK, FirstName, LastName, EmpID). I am only pulling the data for[/color]
> the[color=green]
>> PK and FirstName for my testing purposes (See SQL Statement in code).
>>
>> This is my code (editing.aspx.vb), the first Imports statement starts as
>> Line 1. TIA, Jim
>>
>> Imports System.Data
>> Imports System.Data.OleDb
>>
>> Partial Class tests_editing_editing
>> Inherits System.Web.UI.Page
>> Public Sub EditRecord(ByVal Sender As Object, ByVal E As
>> DataGridCommandEventArgs)
>> employees.EditItemIndex = E.Item.ItemIndex
>> LoadGrid()
>> End Sub
>> Public Sub CancelRecord(ByVal Sender As Object, ByVal E As
>> DataGridCommandEventArgs)
>> employees.EditItemIndex = -1
>> LoadGrid()
>> End Sub
>>
>> Public Sub UpdateRecord(ByVal Sender As Object, ByVal E As
>> DataGridCommandEventArgs)
>> Dim objConnection As OleDbConnection
>> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
>> Source=e:\hhsinternal\tests\editing\editing.mdb"
>>
>> If objConnection Is Nothing Then
>> objConnection = New OleDbConnection(strConnection)
>> End If
>>
>> If objConnection.State = ConnectionState.Closed Then
>> objConnection.Open()
>> End If
>> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>>
>> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
>> Dim ds As New DataSet()
>> adapter.Fill(ds, "TMaster")
>> objConnection.Close()
>>
>> 'Retrieve the field values in the edited row
>> Dim PK As Int32 = Convert.ToInt32(E.Item.Cells(0).Text)
>> Dim FirstNameTextBox As TextBox =[/color]
> CType(E.Item.Cells(1).Controls(0),[color=green]
>> TextBox)
>> Dim FirstName As String = Convert.ToString(FirstNameTextBox.Text)
>>
>> employees.EditItemIndex = -1
>> Update(PK, FirstName)
>>
>> employees.DataSource = ds.tables("TMaster")
>> employees.DataBind()
>>
>> End Sub
>>
>> Public Sub Update(ByVal PK As Int32, ByVal FirstName As String)
>> Dim objConnection As OleDbConnection
>> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
>> Source=e:\hhsinternal\tests\editing\editing.mdb"
>>
>> If objConnection Is Nothing Then
>> objConnection = New OleDbConnection(strConnection)
>> End If
>>
>> If objConnection.State = ConnectionState.Closed Then
>> objConnection.Open()
>> End If
>> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>>
>> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
>> Dim ds As New DataSet()
>> adapter.Fill(ds, "TMaster")
>> objConnection.Close()
>>
>>
>> Dim tbl As DataTable = ds.Tables("TMaster")
>> tbl.PrimaryKey = New DataColumn() _
>> { _
>> tbl.Columns("PK") _
>> }
>> Dim row As DataRow = tbl.Rows.Find(PK)
>> row.Item("FirstName") = FirstName
>>
>> Dim cb As New OleDbCommandBuilder(adapter)
>>
>> objConnection.Open()
>> adapter.Update(ds, "TMaster")
>>
>> objConnection.Close()
>> End Sub
>>
>> Private Sub LoadGrid()
>> Dim objConnection As OleDbConnection
>> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
>> Source=e:\hhsinternal\tests\editing\editing.mdb"
>>
>> If objConnection Is Nothing Then
>> objConnection = New OleDbConnection(strConnection)
>> End If
>>
>> If objConnection.State = ConnectionState.Closed Then
>> objConnection.Open()
>> End If
>>
>> Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"
>>
>> Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
>> Dim ds As New DataSet()
>> adapter.Fill(ds, "TMaster")
>> objConnection.Close()
>>
>> With employees
>> .DataSource = ds.Tables("TMaster")
>> .DataBind()
>> End With
>>
>> End Sub
>>
>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
>> System.EventArgs) Handles Me.Load
>> If Not Page.IsPostBack Then
>> LoadGrid()
>> End If
>> End Sub
>> End Class
>>
>> ===========================================
>> ===========================================
>> Below is the editing.aspx code if needed ..
>> ===========================================
>> ===========================================
>>
>> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="editing.aspx.vb"
>> Inherits="tests_editing_editing" %>
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>>
>> <html xmlns="http://www.w3.org/1999/xhtml" >
>> <head runat="server">
>> <title>Untitled Page</title>
>> </head>
>> <body>
>> <form id="form1" runat="server">
>> <div>
>> <asp:DataGrid ID="employees" runat="server" CellPadding="5"
>> AutoGenerateColumns="false" OnEditCommand="EditRecord"
>> OnCancelCommand="CancelRecord"
>> OnUpdateCommand="UpdateRecord">
>> <Columns>
>> <asp:BoundColumn DataField="PK" ReadOnly="true" Visible="false" />
>> <asp:BoundColumn DataField="FirstName" HeaderText="First Name"
>> ReadOnly="False" />
>> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Save"
>> CancelText="Cancel" EditText="Edit" />
>> </Columns>
>> </asp:DataGrid>
>> </div>
>> </form>
>> </body>
>> </html>
>>
>>
>>
>>
>>[/color]
>
>[/color]


Jim in Arizona
Guest
 
Posts: n/a
#6: Dec 13 '05

re: Operation must use an updateable query ..



"Marina" <someone@nospam.com> wrote in message
news:%23V3g4P2$FHA.504@TK2MSFTNGP12.phx.gbl...[color=blue]
> You didn't define an update query for the adapter to use. It doesn't know
> how to do the update on its own.
>
> You either have to supply the update command, or you have to use an
> OleDBCommandBuilder object. If can do some research on both these
> techniques for more information.
>[/color]

Hi Marina.

Under the Update subroutine:

Public Sub Update(ByVal PK As Int32, ByVal FirstName As String)
Dim objConnection As OleDbConnection
Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=e:\hhsinternal\tests\editing\editing.mdb"

If objConnection Is Nothing Then
objConnection = New OleDbConnection(strConnection)
End If

If objConnection.State = ConnectionState.Closed Then
objConnection.Open()
End If
Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"

Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
Dim ds As New DataSet()
adapter.Fill(ds, "TMaster")
objConnection.Close()


Dim tbl As DataTable = ds.Tables("TMaster")
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("PK") _
}
Dim row As DataRow = tbl.Rows.Find(PK)
row.Item("FirstName") = FirstName

Dim cb As New OleDbCommandBuilder(adapter)

objConnection.Open()
adapter.Update(ds, "TMaster")

objConnection.Close()
End Sub

You can see that I have the cb OleDbCommandBuilder object, although I don't
know if it is being used correctly. Is there more needed to that?


Jim in Arizona
Guest
 
Posts: n/a
#7: Dec 13 '05

re: Operation must use an updateable query ..



"Marina" <someone@nospam.com> wrote in message
news:%23V3g4P2$FHA.504@TK2MSFTNGP12.phx.gbl...[color=blue]
> You didn't define an update query for the adapter to use. It doesn't know
> how to do the update on its own.
>
> You either have to supply the update command, or you have to use an
> OleDBCommandBuilder object. If can do some research on both these
> techniques for more information.
>[/color]

Hi Marina.

Under the Update subroutine:

Public Sub Update(ByVal PK As Int32, ByVal FirstName As String)
Dim objConnection As OleDbConnection
Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=e:\hhsinternal\tests\editing\editing.mdb"

If objConnection Is Nothing Then
objConnection = New OleDbConnection(strConnection)
End If

If objConnection.State = ConnectionState.Closed Then
objConnection.Open()
End If
Dim strSQLSelect As String = "SELECT PK, FirstName FROM TMaster"

Dim adapter As New OleDbDataAdapter(strSQLSelect, objConnection)
Dim ds As New DataSet()
adapter.Fill(ds, "TMaster")
objConnection.Close()


Dim tbl As DataTable = ds.Tables("TMaster")
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("PK") _
}
Dim row As DataRow = tbl.Rows.Find(PK)
row.Item("FirstName") = FirstName

Dim cb As New OleDbCommandBuilder(adapter)

objConnection.Open()
adapter.Update(ds, "TMaster")

objConnection.Close()
End Sub

You can see that I have the cb OleDbCommandBuilder object, although I don't
know if it is being used correctly. Is there more needed to that?


Patrick.O.Ige
Guest
 
Posts: n/a
#8: Dec 13 '05

re: Operation must use an updateable query ..


Jim are you giving the ASPNET acct the right permissions?
Patrick

"Jim in Arizona" <tiltowait@hotmail.com> wrote in message
news:#a4VP2#$FHA.2708@TK2MSFTNGP12.phx.gbl...[color=blue]
>
> "Patrick.O.Ige" <naijacoder@hotmail.com> wrote in message
> news:%233g2Ax6$FHA.3928@tk2msftngp13.phx.gbl...[color=green]
> > Jim i blogged about that error at:-
> > http://spaces.msn.com/members/naijacoder/
> > Look for the Error and read on.
> > Hope that helps
> > PAtrick
> >[/color]
>
> I remember having such issues when I was working with classic ASP and in
> most cases it was security permissions on the access DB. Because of that
> prior experience, I made sure to check the permissions before I posted and
> security permissions are full control for all auth users on our network,[/color]
and[color=blue]
> I'm an admin so have full control anyway. I double check again this[/color]
morning[color=blue]
> to make sure and I still get the same error. I'm at a loss.[color=green]
> > "Jim in Arizona" <tiltowait@hotmail.com> wrote in message
> > news:expPkN2$FHA.1312@TK2MSFTNGP09.phx.gbl...[color=darkred]
> >> I've been using an example out of a book to be able to edit the rows in[/color][/color][/color]
a[color=blue][color=green][color=darkred]
> >> database. I am getting the following error:
> >>
> >> ================================================== ======
> >> ================================================== ======
> >>
> >> Server Error in '/' Application.[/color][/color]
>[color=green]
>> -------------------------------------------------------------------------[/color][/color]
-[color=blue][color=green]
> > ------[color=darkred]
> >> Operation must use an updateable query.
> >> Description: An unhandled exception occurred during the execution of[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> >> current web request. 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 74:
> >> Line 75: objConnection.Open()
> >> Line 76: adapter.Update(ds, "TMaster")
> >> Line 77:
> >> Line 78: objConnection.Close()
> >>
> >> Source File: E:\hhsinternal\tests\editing\editing.aspx.vb Line: 76
> >>
> >> Stack Trace:
> >>
> >> [OleDbException (0x80004005): Operation must use an updateable query.]
> >>[/color]
> >[/color][/color]
System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs[color=blue][color=green][color=darkred]
> >> rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
> >> +1303846
> >>[/color][/color][/color]
System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs[color=blue][color=green][color=darkred]
> >> rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
> >> +46
> >> System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
> >> DataTableMapping tableMapping) +1750
> >> System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable[/color]
> > dataTable,[color=darkred]
> >> DataTableMapping tableMapping) +40
> >> System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String[/color]
> > srcTable)[color=darkred]
> >> +180
> >> tests_editing_editing.Update(Int32 PK, String FirstName) in
> >> E:\hhsinternal\tests\editing\editing.aspx.vb:76
> >> tests_editing_editing.UpdateRecord(Object Sender,
> >> DataGridCommandEventArgs E) in
> >> E:\hhsinternal\tests\editing\editing.aspx.vb:39
> >>[/color]
> >[/color][/color]
System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs[color=blue][color=green][color=darkred]
> >> e) +105
> >> System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source,[/color]
> > EventArgs[color=darkred]
> >> e) +679
> >> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs[/color][/color][/color]
args)[color=blue][color=green]
> > +35[color=darkred]
> >> System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
> >> EventArgs e) +117
> >> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs[/color][/color][/color]
args)[color=blue][color=green]
> > +35[color=darkred]
> >> System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)
> >> +115
> >> System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
> >> eventArgument) +134
> >>[/color]
> >[/color][/color]
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.Rai[color=blue][color=green]
> > sePostBackEvent(String[color=darkred]
> >> eventArgument) +7
> >> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> >> sourceControl, String eventArgument) +11
> >> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)[/color]
> > +180[color=darkred]
> >> System.Web.UI.Page.ProcessRequestMain(Boolean
> >> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
> >> +5670
> >>[/color][/color]
>[color=green]
>> -------------------------------------------------------------------------[/color][/color]
-[color=blue][color=green]
> > ------[color=darkred]
> >> Version Information: Microsoft .NET Framework Version:2.0.50215.44;[/color]
> > ASP.NET[color=darkred]
> >> Version:2.0.50215.44
> >>
> >> ================================================== ======
> >> ================================================== ======
> >>
> >> I can pretty much follow the code, but I don't understand what[/color][/color][/color]
updateably[color=blue][color=green][color=darkred]
> >> query it is referring to.
> >>
> >> Line 75: adapter.Update(ds, "TMaster")
> >>
> >> I have a single MS Access 2003 DB with a single table TMaster and Four
> >> columns (PK, FirstName, LastName, EmpID). I am only pulling the data[/color][/color][/color]
for[color=blue][color=green]
> > the[color=darkred]
> >> PK and FirstName for my testing purposes (See SQL Statement in code).
> >>
> >> This is my code (editing.aspx.vb), the first Imports statement starts[/color][/color][/color]
as[color=blue][color=green][color=darkred]
> >> Line 1. TIA, Jim
> >>
> >> Imports System.Data
> >> Imports System.Data.OleDb
> >>
> >> Partial Class tests_editing_editing
> >> Inherits System.Web.UI.Page
> >> Public Sub EditRecord(ByVal Sender As Object, ByVal E As
> >> DataGridCommandEventArgs)
> >> employees.EditItemIndex = E.Item.ItemIndex
> >> LoadGrid()
> >> End Sub
> >> Public Sub CancelRecord(ByVal Sender As Object, ByVal E As
> >> DataGridCommandEventArgs)
> >> employees.EditItemIndex = -1
> >> LoadGrid()
> >> End Sub
> >>
> >> Public Sub UpdateRecord(ByVal Sender As Object, ByVal E As
> >> DataGridCommandEventArgs)
> >> Dim objConnection As OleDbConnection
> >> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> >> Source=e:\hhsinternal\tests\editing\editing.mdb"
> >>
> >> If objConnection Is Nothing Then
> >> objConnection = New OleDbConnection(strConnection)
> >> End If
> >>
> >> If objConnection.State = ConnectionState.Closed Then
> >> objConnection.Open()
> >> End If
> >> Dim strSQLSelect As String = "SELECT PK, FirstName FROM[/color][/color][/color]
TMaster"[color=blue][color=green][color=darkred]
> >>
> >> Dim adapter As New OleDbDataAdapter(strSQLSelect,[/color][/color][/color]
objConnection)[color=blue][color=green][color=darkred]
> >> Dim ds As New DataSet()
> >> adapter.Fill(ds, "TMaster")
> >> objConnection.Close()
> >>
> >> 'Retrieve the field values in the edited row
> >> Dim PK As Int32 = Convert.ToInt32(E.Item.Cells(0).Text)
> >> Dim FirstNameTextBox As TextBox =[/color]
> > CType(E.Item.Cells(1).Controls(0),[color=darkred]
> >> TextBox)
> >> Dim FirstName As String =[/color][/color][/color]
Convert.ToString(FirstNameTextBox.Text)[color=blue][color=green][color=darkred]
> >>
> >> employees.EditItemIndex = -1
> >> Update(PK, FirstName)
> >>
> >> employees.DataSource = ds.tables("TMaster")
> >> employees.DataBind()
> >>
> >> End Sub
> >>
> >> Public Sub Update(ByVal PK As Int32, ByVal FirstName As String)
> >> Dim objConnection As OleDbConnection
> >> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> >> Source=e:\hhsinternal\tests\editing\editing.mdb"
> >>
> >> If objConnection Is Nothing Then
> >> objConnection = New OleDbConnection(strConnection)
> >> End If
> >>
> >> If objConnection.State = ConnectionState.Closed Then
> >> objConnection.Open()
> >> End If
> >> Dim strSQLSelect As String = "SELECT PK, FirstName FROM[/color][/color][/color]
TMaster"[color=blue][color=green][color=darkred]
> >>
> >> Dim adapter As New OleDbDataAdapter(strSQLSelect,[/color][/color][/color]
objConnection)[color=blue][color=green][color=darkred]
> >> Dim ds As New DataSet()
> >> adapter.Fill(ds, "TMaster")
> >> objConnection.Close()
> >>
> >>
> >> Dim tbl As DataTable = ds.Tables("TMaster")
> >> tbl.PrimaryKey = New DataColumn() _
> >> { _
> >> tbl.Columns("PK") _
> >> }
> >> Dim row As DataRow = tbl.Rows.Find(PK)
> >> row.Item("FirstName") = FirstName
> >>
> >> Dim cb As New OleDbCommandBuilder(adapter)
> >>
> >> objConnection.Open()
> >> adapter.Update(ds, "TMaster")
> >>
> >> objConnection.Close()
> >> End Sub
> >>
> >> Private Sub LoadGrid()
> >> Dim objConnection As OleDbConnection
> >> Dim strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> >> Source=e:\hhsinternal\tests\editing\editing.mdb"
> >>
> >> If objConnection Is Nothing Then
> >> objConnection = New OleDbConnection(strConnection)
> >> End If
> >>
> >> If objConnection.State = ConnectionState.Closed Then
> >> objConnection.Open()
> >> End If
> >>
> >> Dim strSQLSelect As String = "SELECT PK, FirstName FROM[/color][/color][/color]
TMaster"[color=blue][color=green][color=darkred]
> >>
> >> Dim adapter As New OleDbDataAdapter(strSQLSelect,[/color][/color][/color]
objConnection)[color=blue][color=green][color=darkred]
> >> Dim ds As New DataSet()
> >> adapter.Fill(ds, "TMaster")
> >> objConnection.Close()
> >>
> >> With employees
> >> .DataSource = ds.Tables("TMaster")
> >> .DataBind()
> >> End With
> >>
> >> End Sub
> >>
> >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> >> System.EventArgs) Handles Me.Load
> >> If Not Page.IsPostBack Then
> >> LoadGrid()
> >> End If
> >> End Sub
> >> End Class
> >>
> >> ===========================================
> >> ===========================================
> >> Below is the editing.aspx code if needed ..
> >> ===========================================
> >> ===========================================
> >>
> >> <%@ Page Language="VB" AutoEventWireup="false"[/color][/color][/color]
CodeFile="editing.aspx.vb"[color=blue][color=green][color=darkred]
> >> Inherits="tests_editing_editing" %>
> >>
> >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> >>
> >> <html xmlns="http://www.w3.org/1999/xhtml" >
> >> <head runat="server">
> >> <title>Untitled Page</title>
> >> </head>
> >> <body>
> >> <form id="form1" runat="server">
> >> <div>
> >> <asp:DataGrid ID="employees" runat="server" CellPadding="5"
> >> AutoGenerateColumns="false" OnEditCommand="EditRecord"
> >> OnCancelCommand="CancelRecord"
> >> OnUpdateCommand="UpdateRecord">
> >> <Columns>
> >> <asp:BoundColumn DataField="PK" ReadOnly="true" Visible="false" />
> >> <asp:BoundColumn DataField="FirstName" HeaderText="First Name"
> >> ReadOnly="False" />
> >> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Save"
> >> CancelText="Cancel" EditText="Edit" />
> >> </Columns>
> >> </asp:DataGrid>
> >> </div>
> >> </form>
> >> </body>
> >> </html>
> >>
> >>
> >>
> >>
> >>[/color]
> >
> >[/color]
>
>[/color]


Jim in Arizona
Guest
 
Posts: n/a
#9: Dec 13 '05

re: Operation must use an updateable query ..


"Patrick.O.Ige" <naijacoder@toughguy.net> wrote in message
news:%23zbAaI$$FHA.2736@TK2MSFTNGP11.phx.gbl...[color=blue]
> Jim are you giving the ASPNET acct the right permissions?
> Patrick
>[/color]

Well I'll be ...
This is the first time I've actually messed with an access DB and ASP.NET so
I never thought I had to verifiy ASPNET account permissions. That was it
exactly.
Most of my DB programming thus far in ASP.NET has been with SQL.

Thanks Patrick.


Closed Thread