chrepair Posted January 12, 2006 Share Posted January 12, 2006 hello again all.I am simply trying to insert a new record into my data base and keep getting some type of error.Here is the code for the first page...<html><body><form method="post" action="dadd.asp"><table><tr><td>Date:</td><td><input name="da"></td></tr><tr><td>Type First Comment:</td><td><input name="ne"></td></tr><tr></tr><tr></table><br /><br /><input type="submit" value="Add New"> <input type="reset" value="Cancel"></form></body></html>here is the code for the 2nd page...<html><body><%set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open "DATABASEPATH.MDB" ---this is correct on my real pagesql="INSERT INTO greg (Date,New)"sql=sql & " VALUES "sql=sql & "('" & Request.Form("da") & "',"sql=sql & "'" & Request.Form("ne") & "')"on error resume nextconn.Execute sql,recaffectedif err<>3 then Response.Write("No update permissions!")else Response.Write("<h3>" & recaffected & " record added</h3>")end ifconn.close%></body></html>Simpel, right?I have other pages that access this same database and i can change records with no problems, so it's not a"no update permissions" error like I am getting with this code here. Can anyone tell me how to change this code so that I can get an accurate error report as to exactly what kind of error is happening? Also any clues why I am getting an error at all?thnaks. Link to comment Share on other sites More sharing options...
aspnetguy Posted January 13, 2006 Share Posted January 13, 2006 change if err<>3 thenResponse.Write("No update permissions!")else Response.Write("<h3>" & recaffected & " record added</h3>")end if to this Response.Write("<h3>" & recaffected & " record added</h3>") That way we can see the real error that is occuring. Post the error you receive from this. Link to comment Share on other sites More sharing options...
chrepair Posted January 13, 2006 Author Share Posted January 13, 2006 changeif err<>3 thenResponse.Write("No update permissions!")else Response.Write("<h3>" & recaffected & " record added</h3>")end if to this Response.Write("<h3>" & recaffected & " record added</h3>") That way we can see the real error that is occuring. Post the error you receive from this. <{POST_SNAPBACK}> Now i get this...The page cannot be displayed There is a problem with the page you are trying to reach and it cannot be displayed. I took out the error code but the page won't render at all. There is some kinda code problem somewhere.here is the code with that area removed. Must be a typo somewhere.<html><body><%set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open "D:/Websites/Inetpub/Gregs/DBA2/northwind.mdb"sql="INSERT INTO greg (Date,New)"sql=sql & " VALUES "sql=sql & "('" & Request.Form("da") & "',"sql=sql & "'" & Request.Form("ne") & "')"on error resume nextconn.Execute sql,recaffected Response.Write("<h3>" & recaffected & " record added</h3>")end ifconn.close%></body></html> here is the page befrore it...<html><body><form method="post" action="dadd.asp"><table><tr><td>Date:</td><td><input name="da"></td></tr><tr><td>Type First Comment:</td><td><input name="ne"></td></tr><tr></tr><tr></table><br /><br /><input type="submit" value="Add New"> <input type="reset" value="Cancel"></form></body></html>any Idea's? Link to comment Share on other sites More sharing options...
aspnetguy Posted January 13, 2006 Share Posted January 13, 2006 Response.Write("<h3>" & recaffected & " record added</h3>")end ifconn.close%> you need to remove the 'end if' Link to comment Share on other sites More sharing options...
chrepair Posted January 13, 2006 Author Share Posted January 13, 2006 Response.Write("<h3>" & recaffected & " record added</h3>")end ifconn.close%> you need to remove the 'end if' <{POST_SNAPBACK}> Cool.The page works and displays record added but no records have actually been added. There is no error this time though.What are your thoughts? Link to comment Share on other sites More sharing options...
chrepair Posted January 13, 2006 Author Share Posted January 13, 2006 Cool.The page works and displays record added but no records have actually been added. There is no error this time though.What are your thoughts?<{POST_SNAPBACK}> Also I have emailed you private links to the actual forms on the pages if that will help. Link to comment Share on other sites More sharing options...
aspnetguy Posted January 13, 2006 Share Posted January 13, 2006 ok, believe it or not I think there is still an error occuring. I should have seen this earlier.comment out this line on error resume next to 'on error resume next This line is telling the code to continue even though there is an error. This should cause an error and we should see what is really going on.Also The fields Date and New, have you used these in any queries on other pages??? I think Date is a SQL key word. You might want ot try writing it like this INSERT INTO greg ([Date],New) Just a thought, let me know the results of both of those. Link to comment Share on other sites More sharing options...
chrepair Posted January 13, 2006 Author Share Posted January 13, 2006 ok, believe it or not I think there is still an error occuring. I should have seen this earlier.comment out this lineon error resume next to 'on error resume next This line is telling the code to continue even though there is an error. This should cause an error and we should see what is really going on.Also The fields Date and New, have you used these in any queries on other pages??? I think Date is a SQL key word. You might want ot try writing it like this INSERT INTO greg ([Date],New) Just a thought, let me know the results of both of those. <{POST_SNAPBACK}> YOU DA MAN!!!That was the problem. When i first put the ' in front of the error code on the page, the page would not display at all. Then when i added the [] to date the page rendered and now it say "1" record added instead of just record added. When checked the record indeed did add to the data base. Good job thanks a bunch!For my next trick i want to make a form that deletes records and I am sure i will be contacting you about that.As far as formatting goes, if i follow CSS examples will that make things look how i want them to look code wise?Also with this add record page i would like a date to be inseted into the database as the first field and give the uer no option to change that when adding a record but not sure how to go about that one. So that when a users goes to the add page the first "date" field will display the current date(and time) and under that in the "new" field will be where you can type. I was playing with trying to have it auto insert the date but i think this code is written totally wrong for this type of add to database. I also tried formatting the actual database fields in access to a date format which just made the page error then. All my database fields are text as of now.any thoughts? Link to comment Share on other sites More sharing options...
aspnetguy Posted January 13, 2006 Share Posted January 13, 2006 most likely the reason you got an error when inserting in to a datetime field the quotes around the variable.did you insert the variable like this??? sql = "INSERT INTO greg" _ "([Date], New) VALUES(" _ "'" & dateVar &"','" & newVar &"'" I am pretty sure having '1/1/2006' will cause an error.Try this sql = "INSERT INTO greg" _ "([Date], New) VALUES(" _ dateVar &",'" & newVar &"'" The different is I removed the (') from around the dateVar Link to comment Share on other sites More sharing options...
chrepair Posted January 13, 2006 Author Share Posted January 13, 2006 most likely the reason you got an error when inserting in to a datetime field the quotes around the variable.did you insert the variable like this???sql = "INSERT INTO greg" _ "([Date], New) VALUES(" _ "'" & dateVar &"','" & newVar &"'" I am pretty sure having '1/1/2006' will cause an error.Try this sql = "INSERT INTO greg" _ "([Date], New) VALUES(" _ dateVar &",'" & newVar &"'" The different is I removed the (') from around the dateVar <{POST_SNAPBACK}> Thank you once again!I did a little playing with the example you gave me to make this work. I "DIM" the da variable to (DATE()) on the page that posts and used your example that added the variable directly to the database. Then jsut put in the write.responce to display it on the page. I did not know i could directly insert a variable without any " or ( like that. So thanks again!Obviously I need to learn this programming or atleast want to....do you recommend and quick reference guides or books that I can buy that can explain this easily so that even a novice such as myself can understand it and get it working without forum help? I greatly appreciate all your help but i do feel bad continually bugging you with what appears to be trivial information should I have a book to learn from. I have and am learning tons of info from you and I again can't thank you enough! Link to comment Share on other sites More sharing options...
aspnetguy Posted January 13, 2006 Share Posted January 13, 2006 the (') are generally for text only. numbers, dates and other things usually don't work if you add the ('). Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now