Error, Collection is read only

R

ronaldlee

I have this error in Line 89.

Collection is read-only.
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.NotSupportedException: Collection is
read-only.

Source Error:


Line 87: Else
Line 88:
Line 89: objRS.Open("UPDATE Customers SET Customer_Name = '" &
SQL_safe(Request.Form.Item("realname")) & "', customer_Email = '"
& SQL_safe(Request.Form.Item("email")) & "',
Customer_Address_Line1 = '" &
SQL_safe(Request.Form.Item("billing_house")) & "',
Customer_Address_Line2 = '" &
SQL_safe(Request.Form.Item("billing_street")) & "',
Customer_Address_Line3 = '" &
SQL_safe(Request.Form.Item("billing_area")) & "',
Customer_Address_Line4 = '" &
SQL_safe(Request.Form.Item("billing_town")) & "',
Customer_Address_Line5 = '" &
SQL_safe(Request.Form.Item("billing_county")) & "',
Customer_Address_Line6 = '" &
SQL_safe(Request.Form.Item("billing_postcode")) & "',
Customer_Delivery_Address_Line1 = '" &
SQL_safe(Request.Form.Item("delivery_house")) & "',
Customer_Delivery_Address_Line2 = '" &
SQL_safe(Request.Form.Item("delivery_street")) & "',
Customer_Delivery_Address_Line3 = '" &
SQL_safe(Request.Form.Item("delivery_area")) & "',
Customer_Delivery_Address_Line4 = '" &
SQL_safe(Request.Form.Item("delivery_town")) & "',
Customer_Delivery_Address_Line5 = '" &
SQL_safe(Request.Form.Item("delivery_county")) & "',
Customer_Delivery_Address_Line6 = '" &
SQL_safe(Request.Form.Item("delivery_postcode")) & "',
Customer_Telephone = '" &
SQL_safe(Request.Form.Item("telephone")) & "', Customer_Fax = '"
& SQL_safe(Request.Form.Item("fax")) & "' WHERE CustomerID =
" & Session("CustomerID"), objConn)



Stack Trace:


[NotSupportedException: Collection is read-only.]
System.Collections.Specialized.NameValueCollection.Set(String name,
String value) +2029663
System.Collections.Specialized.NameValueCollection.set_Item(String
name, String value) +10
ASP.details_aspx.__Render__control1(HtmlTextWriter __w, Control
parameterContainer) in C:\MySite\details.aspx:89
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
+3153695
System.Web.UI.Page.Render(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter) +23
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +139
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +24
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5916



anyone know why it is read only?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
K

Karl Seguin

Ronald,
I can't see the specific error in the code you've provided. I can tell you
that some collections are read-only, such as Request.Form. This means that
you can store a value into them. For example, you couldn't do this:

Request.Form("firstName") = "someValue"

you can only read from them:

dim firstName as string = Request.Form("firstName")

The error indicates that you are trying to store a value into a read-only
collection. But, looking at the line you provided (not a very nice line by
the way), i can't see the specific instance of this.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


ronaldlee said:
I have this error in Line 89.

Collection is read-only.
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.NotSupportedException: Collection is
read-only.

Source Error:


Line 87: Else
Line 88:
Line 89: objRS.Open("UPDATE Customers SET Customer_Name = '" &
SQL_safe(Request.Form.Item("realname")) & "', customer_Email = '"
& SQL_safe(Request.Form.Item("email")) & "',
Customer_Address_Line1 = '" &
SQL_safe(Request.Form.Item("billing_house")) & "',
Customer_Address_Line2 = '" &
SQL_safe(Request.Form.Item("billing_street")) & "',
Customer_Address_Line3 = '" &
SQL_safe(Request.Form.Item("billing_area")) & "',
Customer_Address_Line4 = '" &
SQL_safe(Request.Form.Item("billing_town")) & "',
Customer_Address_Line5 = '" &
SQL_safe(Request.Form.Item("billing_county")) & "',
Customer_Address_Line6 = '" &
SQL_safe(Request.Form.Item("billing_postcode")) & "',
Customer_Delivery_Address_Line1 = '" &
SQL_safe(Request.Form.Item("delivery_house")) & "',
Customer_Delivery_Address_Line2 = '" &
SQL_safe(Request.Form.Item("delivery_street")) & "',
Customer_Delivery_Address_Line3 = '" &
SQL_safe(Request.Form.Item("delivery_area")) & "',
Customer_Delivery_Address_Line4 = '" &
SQL_safe(Request.Form.Item("delivery_town")) & "',
Customer_Delivery_Address_Line5 = '" &
SQL_safe(Request.Form.Item("delivery_county")) & "',
Customer_Delivery_Address_Line6 = '" &
SQL_safe(Request.Form.Item("delivery_postcode")) & "',
Customer_Telephone = '" &
SQL_safe(Request.Form.Item("telephone")) & "', Customer_Fax = '"
& SQL_safe(Request.Form.Item("fax")) & "' WHERE CustomerID =
" & Session("CustomerID"), objConn)



Stack Trace:


[NotSupportedException: Collection is read-only.]
System.Collections.Specialized.NameValueCollection.Set(String name,
String value) +2029663
System.Collections.Specialized.NameValueCollection.set_Item(String
name, String value) +10
ASP.details_aspx.__Render__control1(HtmlTextWriter __w, Control
parameterContainer) in C:\MySite\details.aspx:89
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
+3153695
System.Web.UI.Page.Render(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter) +23
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +139
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +24
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5916



anyone know why it is read only?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
R

ronaldlee

Do you mind if I send you the whole application so that you can help
me to have a look?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
R

ronaldlee

here is my code


<script language="VB" runat="Server">
Dim objConn As ADODB.Connection
Dim objRS As ADODB.Recordset
Dim dbDNS As String
Dim name As Object
Dim value As Object


Function openDB() As Object
objConn = New ADODB.Connection
objConn.Open("dbfile")

objRS = New ADODB.Recordset
End Function


Function closeDB() As Object
' If the RecordSet has a state of 1 (open) close it
If objRS.state = 1 Then
objRS.Close()
End If

objConn.Close()

'UPGRADE_NOTE: Object objConn may not be destroyed until it is
garbage collected. Copy this link in your browser for more:
'http://msdn.microsoft.com/library/en-us/vbcon/html/vbup1029.asp'
objConn = Nothing
End Function


' Generates the county listing
Function generate_county_list(ByRef name As String, ByRef value As
String, ByRef isDelivery As Byte) As String
' ASP doesn't support associate arrays like Perl and PHP, so need to
use a more messy method
' Created by Stephen Ball

Dim South_West(5) As String
Dim North_West(5) As String
Dim East_Midlands(5) As String
Dim West_Midlands(6) As String
Dim South_Central(6) As String
Dim South_East(6) As String
Dim East_Anglia(6) As String
Dim North_East(5) As String
Dim county As String
Dim data As String

East_Anglia(0) = "Bedfordshire"
East_Anglia(1) = "Cambridgeshire"
East_Anglia(2) = "Essex"
East_Anglia(3) = "Hertfordshire"
East_Anglia(4) = "Norfolk"
East_Anglia(5) = "Suffolk"

East_Midlands(0) = "Derbeyshire"
East_Midlands(1) = "Leicestershire"
East_Midlands(2) = "Lincolnshire"
East_Midlands(3) = "Northamptonshire"
East_Midlands(4) = "Nottinghamshire"

North_East(0) = "Cleveland"
North_East(1) = "Durham"
North_East(2) = "Northumberland"
North_East(3) = "Tyne and Wear"
North_East(4) = "Yorkshire"

West_Midlands(0) = "Herefordshire"
West_Midlands(1) = "Shopshire"
West_Midlands(2) = "Staffordshire"
West_Midlands(3) = "Warickshire"
West_Midlands(4) = "West Midlands"
West_Midlands(5) = "Worcestershire"

North_West(0) = "Cheshire"
North_West(1) = "Cumbria"
North_West(2) = "Greater Manchester"
North_West(3) = "Lancashire"
North_West(4) = "Merseyside"

South_Central(0) = "Berkshire"
South_Central(1) = "Dorset"
South_Central(2) = "Hampshire"
South_Central(3) = "Isle of White"
South_Central(4) = "Oxfordshire"
South_Central(5) = "West Sussex"

South_East(0) = "Buckinghamshire"
South_East(1) = "East Sussex"
South_East(2) = "Greater London"
South_East(3) = "Kent"
South_East(4) = "Middlesex"
South_East(5) = "Surrey"

South_West(0) = "Cornwall"
South_West(1) = "Devon"
South_West(2) = "Gloucestershire"
South_West(3) = "Somerset"
South_West(4) = "Wiltshire"

If isDelivery = 1 Then
data = "<select name=""" & name & """
onchange=""uncheck_billing();"">"
Else
data = "<select name=""" & name & """>"
End If

data = data & "<option value="""">Select a
county:</option>"

' Generate the East Anglia List
data = data & "<optgroup label=""East Anglia"">"
For Each county In East_Anglia
data = data & create_list(county, value)
Next county

' Generate the East Midlands List
data = data & "<optgroup label=""East Midlands"">"
For Each county In East_Midlands
data = data & create_list(county, value)
Next county

' Generate the North East List
data = data & "<optgroup label=""North East"">"
For Each county In North_East
data = data & create_list(county, value)
Next county

' Generate the West Midlands List
data = data & "<optgroup label=""West Midlands"">"
For Each county In West_Midlands
data = data & create_list(county, value)
Next county

' Generate the North West List
data = data & "<optgroup label=""North West"">"
For Each county In North_West
data = data & create_list(county, value)
Next county

' Generate the South Central List
data = data & "<optgroup label=""South Central"">"
For Each county In South_Central
data = data & create_list(county, value)
Next county

' Generate the South East List
data = data & "<optgroup label=""South East"">"
For Each county In South_East
data = data & create_list(county, value)
Next county

' Generate the South West List
data = data & "<optgroup label=""South West"">"
For Each county In South_West
data = data & create_list(county, value)
Next county

data = data & "</select>"
generate_county_list = data

End Function


' Generates the option value
Function create_list(ByRef county As String, ByRef current As String)
As String
Dim data As String

If county <> "" Then
If county = current Then
data = data & "<option value=""" & county & """
selected=""selected"">" & county & "</option>"
Else
data = data & "<option value=""" & county & """>"
& county & "</option>"
End If
End If

create_list = data
End Function


' A function to make data SQL safe, replace ' with ''
Function SQL_safe(ByRef data As String) As String
data = Replace(data, "'", "''")

SQL_safe = data
End Function

</script>
<%

dbDNS = "COMP224_Assignment_Database"
%>



hope this helps

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
K

Karl Seguin

Ronald,
In the other post, Brad said that the problem might be that your ADODB
recordset is using a forward-only cursor, which would make an update
illegal. From the code you provided, you aren't specifying a cursor type
and forward-only is the default. Looks like brad might be right. I haven't
done ADODB in a long time, but try to set the recordset's cursor to Dynamic

I really don't know if this will work, but try:

Function openDB() As Object
objConn = New ADODB.Connection
objConn.Open("dbfile")

objRS = New ADODB.Recordset
objRS.CursorType = ADODB.CursorTypeEnum.adOpenDynamic ' <-- ADDED THIS
LINE
End Function


Karl
 
R

ronaldlee

HI,
how to do a RecordSet in OleDbConnection???
my original code is using ADODB.RecordSet
But how can i do the RecordSet in OleDbConnection?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
K

Karl Seguin

The closest thing to a recordset in ADO.Net is the DataReader

OleDbConnection conn = new OleDbConnection("CONNECTION STRING")
OleDbCommand command = new OleDbCommand("SELECT * FROM SomeTable", conn)
conn.open()
OleDbDataReader dr = command.ExecuteReader()
while dr.read()
dim someValue as string = cstr(dr("someColumnName"))
end while
dr.close()
conn.dispose()
command.dispose()

with the error checking removed..

Karl
 
R

ronaldlee

Hi
I don;t understand this line
Dim someValue As String = CStr(dr("someColumnName")) <- what column
name? I got all the column name in my database.

Do you mind if I send you the code by email?
my email: (e-mail address removed)
Please email me so that I can send you the code

I have to hand in this application before 23 Dec. So I am in a hurry.
I am really appreciate that you help me. Thanks for your help

Ron

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
K

Karl Seguin

I'm sorry Ronald, but you'll need to figure it out yourself.

dim someValue as string = cstr(dr("someColumnName"))

simply shows how to access a value from the datareader. "someColumnName" is
the name of the database column you selected...like:

select firstName, lastName from User

you would use dr("firstName") to get the first name of the row..

Karl
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top