'Operation must be an updateable query'

  • Thread starter One Handed Man \( OHM - Terry Burns \)
  • Start date
O

One Handed Man \( OHM - Terry Burns \)

OK Folks, its not very often that I ask a question, but I think I'm missing
something and I just cant seem to see it, Im very tired so some help would
be appreciated.

I have a webform with a DataGrid on it. In the DataGrid1.UpdateCommand, I am
setting a very simple update command

"UPDATE tblUsers SET FirstName='Manuel' WHERE UserID=1"

Now, I have tried the same technique from a windows forms application and
it works fine, why might I be getting this Exception


'Operation must be an updateable query'

When I execute the UpdateCommand.ExecuteNonQuery

I hate asking for help, but when your working on your own for hours on end,
sometimes it helps to talk to another !





--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
G

Greg Burns

If executing against an Access database, perhaps a permissions error for the
ASP.NET user for the .mdb file? (I usually put access files in their own
subfolder and give ASP.NET modify rights to folder. That way the .ldb file
can be created)

Just a guess,
Greg
 
C

Cor Ligthert

Hi Terry,

I made a complete test with every on it even a datagrid, an insert, a
datareader and your update.
No problems at all even with exactly the same text as you.

So as Mariana said show some code, (when you want it, you see my email
adres, however tomorrow I have almost no time)

Cor
 
O

One Handed Man \( OHM - Terry Burns \)

I'm givin up for tonight. . . Here's the code.

Cheers

Public Class WebForm1
Inherits System.Web.UI.Page

Private Con As New System.Data.OleDb.OleDbConnection("Data
Source=C:\ASPNET\Banking.mdb;Provider=Microsoft.Jet.OLEDB.4.0;")
Private SelectCommand As New System.Data.OleDb.OleDbCommand
Private UpdateCommand As New System.Data.OleDb.OleDbCommand
Private DS1 As New DS
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Private DA As New System.Data.OleDb.OleDbDataAdapter

Private Sub FillDataSet()

'Select Command
SelectCommand.CommandText = "SELECT * FROM tblUsers"
SelectCommand.Connection = Con

DA.SelectCommand = SelectCommand
DataGrid1.DataSource = DS1.Tables("tblUsers")

Try
Con.Open()
DS1.Clear()
DA.Fill(DS1, "tblUsers")
DataGrid1.DataBind()
Catch ex As Exception
Label1.Text = ex.Message
Finally
Con.Close()
End Try


End Sub


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then Me.FillDataSet()

End Sub
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.EditCommand
Label1.Text = "Im in Edit"
Me.FillDataSet()
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()

End Sub

Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.DeleteCommand
Label1.Text = "Im in Delete"
End Sub

Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.UpdateCommand
Label1.Text = "I'm In Update"

Dim UpdateCommand As New System.Data.OleDb.OleDbCommand


DA.UpdateCommand = UpdateCommand

Try
Con.Open()
UpdateCommand.Connection = Con
UpdateCommand.CommandText = "UPDATE tblUsers SET
FirstName='GARY' WHERE UserID=1"
'DA.Update(DS1, "tblUSers")

Label1.Text = UpdateCommand.ExecuteNonQuery
'^^^^^^^^ FAILS HERE ^^^^^^^^^^^
DataGrid1.EditItemIndex = -1
Me.FillDataSet()

'At End
'DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
Catch ex As Exception
Label1.Text = ex.Message
Finally
Con.Close()
End Try
End Sub
End Class


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
M

Marina

I can't see anything obviously wrong, so I would then go with what Greg
suggested, which is that ASP.NET does not have sufficient rights to modify
that file. Make sure that it does.
 
O

One Handed Man \( OHM - Terry Burns \)

Yep, that was it. Permissions are a little bit more convoluted to do on XP
because by default simple file sharing is switched on.

Fixed - Thanks everyone

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top