Jump to content

Update Record Set


paulonu

Recommended Posts

Hello,I'm taking my first few steps in the asp playground and I need a little help understading why my page is hanging on the record set update. Can anyone help me troubleshoot? I stepped thru the page line by line and the error comes up after: rsAddComments.UpdateBest,NewbieDev

<%'Dimension variablesDim adoCon             'Holds the Database Connection ObjectDim rsAddComments  'Holds the recordset for the new record to be addedDim strSQL              'Holds the SQL query to query the database'Create an ADO connection objectSet adoCon = Server.CreateObject("ADODB.Connection")'Set an active connection to the Connection object using a DSN-less connectionadoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")'Create an ADO recordset objectSet rsAddComments = Server.CreateObject("ADODB.Recordset")'Initialise the strSQL variable with an SQL statement to query the databasestrSQL = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"'Set the cursor type we are using so we can navigate through the recordsetrsAddComments.CursorType = 2'Set the lock type so that the record is locked by ADO when it is updatedrsAddComments.LockType = 3'Open the recordset with the SQL query rsAddComments.Open strSQL, adoCon'Tell the recordset we are adding a new record to itrsAddComments.AddNew'Add a new record to the recordsetrsAddComments.Fields("Name") = Request.Form("name")rsAddComments.Fields("Comments") = Request.Form("comments")'Write the updated recordset to the databasersAddComments.Update'Reset server objectsrsAddComments.CloseSet rsAddComments = NothingSet adoCon = Nothing'Redirect to the guestbook.asp pageResponse.Redirect "guestbook.asp"%>
Link to comment
Share on other sites

I suggest you to use INSERT command instead of adNew in your SQL. AdNew doesn't work in many cases, may cause problems etc.

...Set rsAddComments = Server.CreateObject ("ADODB.Command")	rsAddComments.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")	rsAddComments.CommandText = "INSERT INTO tblComments (Name, Comments) VALUES ('" & Request.Form("name") & "', '" & Request.Form("comments") & "')"	rsAddComments.CommandType = 1	rsAddComments.CommandTimeout = 0	rsAddComments.Prepared = true	rsAddComments.Execute()...

Try it this way, I hope this will work well for you.Redsun

  • Like 1
Link to comment
Share on other sites

I suggest you to use INSERT command instead of adNew in your SQL. AdNew doesn't work in many cases, may cause problems etc.
...Set rsAddComments = Server.CreateObject ("ADODB.Command")	rsAddComments.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")	rsAddComments.CommandText = "INSERT INTO tblComments (Name, Comments) VALUES ('" & Request.Form("name") & "', '" & Request.Form("comments") & "')"	rsAddComments.CommandType = 1	rsAddComments.CommandTimeout = 0	rsAddComments.Prepared = true	rsAddComments.Execute()...

Try it this way, I hope this will work well for you.Redsun

Hi Redsun,Thanks for your help. I used your suggestion but still get an error on the page. This is what my code looks like. Am I missing something?
<%'Dimension variablesDim adoCon			 'Holds the Database Connection ObjectDim rsAddComments  'Holds the recordset for the new record to be addedDim strSQL			  'Holds the SQL query to query the databaseSet rsAddComments = Server.CreateObject ("ADODB.Command")rsAddComments.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")rsAddComments.CommandText = "INSERT INTO tblComments (Name, Comments) VALUES ('" & Request.Form("name") & "', '" & Request.Form("comments") & "')"rsAddComments.CommandType = 1rsAddComments.CommandTimeout = 0rsAddComments.Prepared = truersAddComments.Execute()%>

I also tried adding the RS.update line at the end. But that didn't work either.

'Write the updated recordset to the databasersAddComments.Update'Reset server objectsrsAddComments.CloseSet rsAddComments = NothingSet adoCon = Nothing'Redirect to the guestbook.asp pageResponse.Redirect "guestbook.asp"

Link to comment
Share on other sites

You should completely remove these parts of code (some of them are irrelevant because they are used in recordsets, but you are executing INSERT command; some are not present in the code bellow):

'Dimension variablesDim adoCon			 'Holds the Database Connection ObjectDim rsAddComments  'Holds the recordset for the new record to be addedDim strSQL			  'Holds the SQL query to query the database

and

'Write the updated recordset to the databasersAddComments.Update'Reset server objectsrsAddComments.CloseSet rsAddComments = NothingSet adoCon = Nothing

Post your error message and assing error line number too please, it could containt some useful information.Also make sure that the values posted in your form fit to your DB columns (for example adding TEXT value into INT column or something like this).Redsun

Link to comment
Share on other sites

Uhm, there's still some error… and no concrete error code is displayed.It seems to me that you use Internet Explorer and I guess that you have 'Display detailed error messages' option ON so you do not see the exact error message sent from IIS. So you can't go to concrete line number in your code and repair the error (in fact IIS debbuger shows line number where's the error, but IE could hide this error from you).You can use Firefox or Opera to access your page or you can turn this option OFF in IE (Tools —> Internet Settings —> Details (last fold) —> (node called) Browsing —> Display detailed error messages —> OFF). Reload your page. Then post your error msg.(Sorry if the there are a little different exact names in Tools menu, I have non-english version of IE.)Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...