J
Jim in Arizona
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.UpdatedRowStatusErrors(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.UpdateFromDataTable(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(Object source, EventArgs
e) +679
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +134
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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>
<aspataGrid 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>
</aspataGrid>
</div>
</form>
</body>
</html>
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.UpdatedRowStatusErrors(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.UpdateFromDataTable(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(Object source, EventArgs
e) +679
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +134
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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>
<aspataGrid 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>
</aspataGrid>
</div>
</form>
</body>
</html>