-
What a nightmare... RSAddrecord.AddNew what is wrong with this..
---------------------------------------------------
Private Function AddRecord()
Dim strConn
Dim strQuery
Dim i
Dim RSAddrecord
' Create our connection string
strConn = GetConnectionString()
strQuery="SELECT * FROM SUGGESTION"
Set RSAddRecord = createObject("ADODB.Recordset")
RSAddRecord.Open strQuery,strConn,3 'open as clientside cursor
RSAddrecord.AddNew
FOR i = 1 to RS.Fields.Count -1
'RS.Fields(i).Value = RS.Fields(i).Name
RSAddrecord.Fields(i).Value = session("field_1(i).Value")
NEXT
RSAddrecord.Update
End Function
How do i check if recordset is read only?
Many thanks
Gary
-
Hi Gary,
I have observed the following in ur code and frankly i am not in a position to comment but i want you to check them out.
i) You are using a 1-based array bound i.e.,
in the for loop you are using 1 to count - 1 which would give you one less field (i suppose).
Even if you set option base 1 you have to use from 1 to count, if it is option base 0 then 0 to count - 1.
ii) You have specified the cursor location by setting aduseclient, but you havent specified the type which should be either dynamic or keyset type to be able to add new values.
iii) I think one of the options in the type specification is readonly.
Hope this observation is correct and is useful to u.
Please correct me if i am wrong.
All the best...vijay.
-
You have to specify one more parameter on your recordset.open line- Locking Type. If your updating, you can use adLockOptimistic. Default if not specified is read only (which is why your update fails)
-
Hi monte96, can i now presume now that my observations are correct. Please do reply and encourage me...vijay
-
Well.. mostly.. the syntax for the open method on a recordset is:
rst.open SQL, Connection (Object- not the string), CursorType, LockingType
To specify cursor location you can use:
rst.CursorLocation = adUseClient
In his RSAddRecord.Open strQuery,strConn,3 'open as clientside cursor
It is NOT opening as a client side cursor, but rather setting adOpenStatic for the cursorType along with a default read only lock type.
-
Advice welcome
strQuery="SELECT * FROM SUGGESTION"
'create object
set objConn = createObject("ADODB.Connection")
'open connection to DB
objConn.Open strConn
'reate recordset
Set RSAddRecord = createObject("ADODB.Recordset")
'create active connection from recordset to cennection of DB
RSAddrecord.Source = strQuery
RSAddrecord.Open,objConn,3,2
'RSAddRecord.Open strQuery,strConn,3 'open as clientside cursor
if Not IsEmpty(Request.Form) then
else
RSAddrecord.AddNew
FOR i = 1 to RSAddrecord.Fields.Count -1
'RS.Fields(i).Value = RS.Fields(i).Name
RSAddrecord.Fields(i).Value = session("fields")
NEXT
RSAddrecord.Update
end if
********************************************************8
How does this look?
Monte96 i have to set the for loop like this other wise i get this error
Microsoft OLE DB Provider for ODBC Drivers error '80040e21'
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
/mlintranetsite/suggestion.asp, line 150
How can i get information from the form that i produce on-the-fly? i use this loop to create the form this is a world i am new to so i respect your patient.
Many Thanks
-
efficent code
Can anyone tell me how to create a form on the fly and take the values over to another function
code at present***********************
Private Function CreateFormEntry()
Dim strQuery ' SQL String
Dim RS ' Recordset object
Dim cn 'adodb.connection
Dim strConn
Dim StrSort
Dim objConn
Dim FieldAmount
'This section sorts .
if request.form("sort")<> "" THEN
StrSort=request.form("sort")
ELSE
StrSort="ID"
END IF
' Create our connection string
strConn = GetConnectionString()
strQuery="SELECT * FROM SUGGESTION"
'create object
set objConn = createObject("ADODB.Connection")
'open connection to DB
objConn.Open strConn
'reate recordset
Set RS = createObject("ADODB.Recordset")
'create active connection from recordset to cennection of DB
RS.Source = strQuery
RS.Open,objConn,3,2
%>
<h3>Suggestions Box</h3>
<form name="SUGGESTION" action="/mlintranetsite/suggestion.asp?pageid=view" method="POST">
<table border=1 bordercolor="#e70f7f" cellspacing=1 cellpadding=1 rules=box>
<%
ON ERROR RESUME NEXT
IF RS.eof THEN
Response.Write "There are no entries in the database."
ELSE
%>
<tr>
<%
FOR i = 1 to RS.Fields.count - 1
Response.Write "<td><p><b>" & RS(i).Name & "<b></p></td>"
NEXT
FieldAmount = i
'WHILE NOT RS.EOF
%>
</tr>
<tr>
<%
FOR i = 1 to FieldAmount -1
Response.Write "<td><input type=text name=" & RS(i).Name & " value=" & RS(i).Value & "></B></td>"
NEXT
RS.MoveNext
%>
</tr>
<%
'WEND
RS.Close
END IF
%>
</table>
</form>
<%
AddRecordButton
ShowSearchFormButton
End Function
-
FOR i = 1 to FieldAmount -1
Response.Write "<td><input type=text name=" & RS(i).Name & " value=" & "RS(i).Value" & "></B></td>"
NEXT
RS.MoveNext
Anyone tell me how to convert this so i can retrieve the values in a form into a session array
-
Generally, you would not want to put data into an array in the session object. Submitting the form will allow you to access the data from it in your page that is specified in the action attribute of the FORM collection. Just out of curiousity, why would you want to build a form this way? You should know the field structure of your database before you are accessing it.
Now, if your trying to display multiple records to have the ability to be modified, the best solution I've found is using a loop and creating the same form repeatedly, each with their own submit button. Even with the same name, the server is able to determine which one was submitted. (I use a hidden textbox to store the primary key of each record in the form, so I know which record to update)
But, even using this method, I use hard coded name attributes for my form elements. Otherwise, you will have a difficult time accessing the data since you will need the name of the element when retrieving it from the form collection.