Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 April 26th, 2008, 08:43 AM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 124
Thanks: 0
Thanked 1 Time in 1 Post
Default Error msg:Operation must use an updateable query .

The codes are shown below. For this example, instead of coding btn_click, 'Page_isPostBack then InsertRecord()'
was coded to run the databae updating.

Sub Page_Load(sender As Object, e As EventArgs)
If Page.IsPostBack Then
InsertRecord()
End If
End Sub

What's wrong with this Sub InsertRecord()?

TIA,
Jeffrey

Sub InsertRecord()
Dim conClasf As OleDbConnection
Dim cmdClasf As New OleDbCommand
Dim strClasf As String
Dim strSQL As String
Dim intRowsAff As Integer
lblErrMsg.Text = ""
lblRecsAff.Text = ""

strClasf = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & _
Server.MapPath("/App_Data/classified.mdb") & ";"
conClasf = New OleDbConnection(strClasf)
conClasf.Open
Randomize

strSQL = "INSERT INTO members (" & _
"memberid, " & _
"firstname, " & _
"lastname, " & _
"[password], " & _
"confnumber, " & _
"confirmed " & _
") VALUES ('" & _
Replace(txtMemberid.Value, "'", "''") & _
"', '" & _
Replace(txtFirstname.Value, "'", "''") & _
"', '" & _
Replace(txtLastname.Value, "'", "''") & _
"', '" & _
Replace(txtPassword.Value, "'", "''") & _
"', " & _
Clng(Rnd() * 9000000) + 1000000 & _
", " & _
"False) "

cmdClasf = New OleDbCommand(strSQL, conClasf)
TryintRowsAff = cmdClasf.ExecuteNonQuery()
Catch ex As Exception
lblErrMsg.Text = ex.Message
End Try
lblRecsAff.Text = intRowsAff & " record(s) inserted"
conClasf.Close
End Sub
__________________
C. Jeffrey Wang
 
Old April 26th, 2008, 10:08 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I've seen this error when the web process doesn't have the necessary rights to write to the MDB file. This is a possible cause.

I would highly recommend you look at some tutorials on using the parameters collection of the OleDbCommand class for your queries. You are manually constructing the SQL syntax which is difficult to read (for humans at least). I see that you have taken consideration for escaping the ' character. Parameters take care of that for you and make your code much easier to understand.

-Peter
peterlanoie.blog
 
Old April 27th, 2008, 02:10 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look here: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=263

HtH,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Operation must use an updateable query sandhya12_rcnair ASP.NET 2.0 Professional 3 November 11th, 2008 11:56 AM
Operation must use an updateable query darkhalf Access 4 February 29th, 2008 12:50 PM
Operation must use an updateable query hchlebowski ASP.NET 1.0 and 1.1 Basics 1 January 24th, 2006 07:11 AM
Operation must use an updateable query chaos2003 Classic ASP Databases 4 August 22nd, 2003 03:04 PM
Operation must use an updateable query error bnlmike Classic ASP Databases 1 July 16th, 2003 04:21 AM





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