Link to home
Start Free TrialLog in
Avatar of fosiul01
fosiul01Flag for United Kingdom of Great Britain and Northern Ireland

asked on

need help to fix a bug in code

Hi, i took this code from web sites, about CMS system.
now when i run the page, Pages can read the data from table, but when i  am trying to save or Edit, its giving following error  and also i have attached the code as well, since, this is not my code and  i am not so good in asp.net thats why i am asking if any one can fix the problem for me.


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 50:             Dim iCmd As New OleDbCommand(strSQL, iconn)
Line 51:                iConn.Open()
Line 52:           iCmd.ExecuteReader()
Line 53:           iConn.Close()
Line 54:       end if


Source File: c:\inetpub\wwwroot\cms\list.aspx    Line: 52

Stack Trace:

[OleDbException (0x80004005): Operation must use an updateable query.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +267
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +192
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +48
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +106
   System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +111
   System.Data.OleDb.OleDbCommand.ExecuteReader() +6
   ASP.cms_list_aspx.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\cms\list.aspx:52
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
<%@ Page Language="vb" Debug=true %>
<%@ import Namespace="System.Data.OLEDB" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Page List</title>
<style>
	.myfont {
		background-color : White;
		font-family : Arial, Helvetica, sans-serif;
	}
</style>
<!-- #INCLUDE FILE="include.aspx" -->
<!-- #INCLUDE FILE="menu.aspx" -->
<script runat="server" language="vb">
	Sub btnHelp_OnClick(Src As Object, E As EventArgs)
		lblhelp.visible = true
	End Sub
 
    Sub Page_Load(sender As Object, e As EventArgs)
	lblhelp.Visible = False
	if session("loggedin") = "" then
		response.redirect("login.aspx")
	end if
 
	dim homepage as integer = request.querystring("homepage")
	dim homepageid as integer = request.querystring("id")
	if homepage = 1 then
		  'set all to 0 '
	  	  Dim strSQL As String = "UPDATE tblPages SET homepage = 0;"
	  	  Dim iConn As New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbsource)
    	  Dim iCmd As New OleDbCommand(strSQL, iconn)
       	  iConn.Open()
          iCmd.ExecuteReader()
          iConn.Close()
		 'set homepage '
	  	  Dim strSQL2 As String = "UPDATE tblPages SET homepage = 1 where ID = " & homepageid & ";"
	  	  Dim iConn2 As New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbsource)
    	  Dim iCmd2 As New OleDbCommand(strSQL2, iconn2)
       	  iConn2.Open()
          iCmd2.ExecuteReader()
          iConn2.Close()
	end if
	
 
	dim newpage as integer = request.querystring("newpage")
	if newpage = 1 then
	  	  Dim strSQL As String = "INSERT INTO tblPages(pagename, pagedata, homepage) VALUES('*new page description*', '<html>" & vbcrlf & "<head>" & vbcrlf & "<title>Untitled</title>" & vbcrlf & vbcrlf & "</head>" & vbcrlf & "<body>" & vbcrlf & vbcrlf & vbcrlf & "</body>" & vbcrlf & "</html>', 0);"
	  	  Dim iConn As New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbsource)
    	  Dim iCmd As New OleDbCommand(strSQL, iconn)
       	  iConn.Open()
          iCmd.ExecuteReader()
          iConn.Close()
	end if
	
	dim deleteid as integer = request.querystring("deleteid")
	if deleteid > 0 then
	      Dim queryvalue = Request.QueryString("deleteid")
	  	  Dim strSQL As String = "DELETE FROM tblPages WHERE ID = " & queryvalue & ";"
	  	  Dim dconn As New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbsource)
    	  Dim iCmd As New OleDbCommand(strSQL, dconn)
       	  dconn.Open()
          iCmd.ExecuteReader()
          dconn.Close()
	end if
 
        Dim query As String = "Select pagename,id,homepage FROM tblpages order by pagename;"
        Dim myConn As New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbsource & "")
        Dim Cmd as New OLEDBCommand(query,myConn)
        MyConn.Open()
        dim dbread
		dbread=Cmd.ExecuteReader()
		tblpages.DataSource=dbread
		tblpages.DataBind()
		dbread.Close()
		myconn.Close()
		dim numberofresults as string = tblpages.Items.Count
		lblrcount.text = numberofresults & " pages found"
		dim idvalue as string = id
 
	End Sub
 
</script>
<body style="font-family: Arial, Helvetica, sans-serif;">
<h3 class="myfont" title="visit www.basic-cms.com for updates">Basic CMS - Page Management</h3>
<p><a href="list.aspx?newpage=1" title="click here to create a new page">Create New Page</a></p>
<asp:Repeater id="tblpages" runat="server">
<HeaderTemplate>
<table border="1" cellspacing="0" cellpadding="4" bordercolor="#000000" class="myfont">
<tr bgcolor="#b0c4de">
	<th>ID</th>
	<th>Page Description</th>
	<th>Default</th>
	<th>URL</th>
	<th>Edit</th>
	<th>Delete</th>
</tr>
</HeaderTemplate>
 
<AlternatingItemTemplate>
<tr bgcolor="#FFFFFF">
	<td><%#Container.DataItem("id")%>&nbsp;</td>
	<td><%#Container.DataItem("pagename")%>&nbsp;</td>
	<td><a href="list.aspx?id=<%#Container.DataItem("id")%>&homepage=1" title="Click to set as home page"><%#Container.DataItem("homepage")%></a>&nbsp;</td>
	<td><a href="default.aspx?id=<%#Container.DataItem("id")%>" title="default.aspx?id=<%#Container.DataItem("id")%>" target="_blank">default.aspx?id=<%#Container.DataItem("id")%></td>
	<td><a href="edit.aspx?id=<%#Container.DataItem("id")%>" title="Click to Edit">Edit</a>&nbsp;</td>
	<td><a href="list.aspx?deleteid=<%#Container.DataItem("id")%>" title="Delete!">Delete</a></td>
</tr>
</AlternatingItemTemplate>
 
<ItemTemplate>
<tr bgcolor="#f0f0f0">
	<td><%#Container.DataItem("id")%>&nbsp;</td>
	<td><%#Container.DataItem("pagename")%>&nbsp;</td>
	<td><a href="list.aspx?id=<%#Container.DataItem("id")%>&homepage=1" title="Click to set as home page"><%#Container.DataItem("homepage")%></a>&nbsp;</td>
	<td><a href="default.aspx?id=<%#Container.DataItem("id")%>" title="default.aspx?id=<%#Container.DataItem("id")%>" target="_blank">default.aspx?id=<%#Container.DataItem("id")%></td>
	<td><a href="edit.aspx?id=<%#Container.DataItem("id")%>" title="Click to Edit">Edit</a>&nbsp;</td>
	<td><a href="list.aspx?deleteid=<%#Container.DataItem("id")%>" title="Delete!" onclick="return confirm('Are you sure you want to delete?')">Delete</a></td>
</tr>
</ItemTemplate>
 
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
&nbsp;<asp:Label Id="lblrcount" RunAt="server" CssClass="myfont" ForeColor="#000000" font-size="12" />
 
<form runat="server">
	<asp:Button Id="btnShowHelp" RunAt="server" Text="Help" OnClick="btnHelp_OnClick" class="myfont" title="click for basic help" />
</form>
 
<asp:Label Id="lblhelp" RunAt="server" class="myfont" Text="<p><strong>Page Name:</strong> The page description</p><p><strong>Default:</strong> 1=default, or start page. Click to set.</p><p><strong>URL:</strong> To link to this page, use this location.</p><p><strong>Edit:</strong> Click Edit to edit the page.</p><p><strong>Delete:</strong> Click Delete to delete the page.</p>" />
 
<p><small><a href="http://www.basic-cms.com" title="basic content management" target="_blank">powered by basic-cms</a></small></p>
 
</body>
</html>

Open in new window

SOLUTION
Avatar of ZachSmith
ZachSmith
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fosiul01

ASKER

Hi i tryed, its saying the same thing

Line 50:             Dim iCmd As New OleDbCommand(strSQL, iconn)
Line 51:                iConn.Open()
Line 52:             iCmd.ExecuteNonQuery()
Line 53:           iConn.Close()
Line 54:       end if
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, its funny, actaully i didnot understood what happended at all, but i will explain

i used iCmd.ExecuteNonQuery(), but if i run this one from http://localhost/ its not working . but  if i try to run from vb.net by clicking run button, it wil run.!!!

what i did  is : i  open the folder under vb.net 2005 , and try to run from their, so it added a webconfig file automaticaly, and from their  its working fine, every functions are running.

i will check further more after going home ,
will come back with feedback give me few hrs time please


 
I have a feeling this is a permissions issue with the database file. Are you accessing an Access database?
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, zachsmith and GreenGhost, thanks for reply and advise
yes its a permission issue of database,
I am using Access database, and when i gave aspnet and isuer full control its works fine

but

there is one problem .
i copied same file to 2 different folder one is cms and cms1

Cms has webconfig file and cms1 its without webconfig

now cms1 is running fine after giving permission.

problme is cms - its running fine under vb.net
but if i try to run from localhost, its giving following error :

Server Error in '/' Application.
--------------------------------------------------------------------------------

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS.

Source Error:


Line 24:             ASP.NET to identify an incoming user.
Line 25:         -->
Line 26:             <authentication mode="Windows"/>
Line 27:             <!--
Line 28:             The <customErrors> section enables configuration
 

Source File: c:\inetpub\wwwroot\cms\web.config    Line: 26


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

would you please tell me why is that ??
This new problem is because the cms folder is not an application in IIS. It's a subfolder in the application, but the web.config has to be in the root folder of the application to work.

Open the properties for the cms folder in IIS and press the Create button to make it an application.
owo!!! its done!!
how the hell you know all these things!!!
thats call experience!!!

anyway, thanks for helping me out.