mckenzie Posted May 5, 2006 Share Posted May 5, 2006 Out of present range.AddOrder.asp, line 42I don't understand this error sorry if its obvious.This is the code for my addorder page. can anyone help me?<%Dim connDim CmdPopulatefoodDim SQLdim FieldNamedim TableNameset Conn = Server.createobject("ADODB.Connection")conn.open "PROVIDER=Microsoft.jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("Project1.mdb") & ";" Set rs = Server.CreateObject("ADODB.RecordSet")dim fnamedim amntdim totalitemsdim linecostdim totalcostdim orderiddim count count = 0 for i = 1 to 19linecost = 0fname=Request.QueryString("txt" & i)amnt=Request.QueryString("amnt" & i) If fname<>"" Then count = count + 1 Response.Write("Hello " & fname & " X " & amnt & "!<br />") totalitmes = totalitmes + amnt linecost = fname * amnt totalcost = totalcost + linecost End Ifnextif count > 0 then SQL= "SELECT * FROM ORDER_HEAD ;" rs.CursorType = 2 rs.LockType = 3 rs.Open SQL, Conn rs.AddNew rs.Fields("NO OF ITEMS") = totalitmes rs.Fields("TOTAL PRICE") = totalcost rs.Fields("DATE") = date() rs.Update orderid = rs.Fields("ORDER ID") rs.Close SQL= "SELECT * FROM ORDER_DETAILS ;" rs.CursorType = 2 rs.LockType = 3 rs.Open SQL, Conn for i = 1 to 19 linecost = 0 fname=Request.QueryString("txt" & i) amnt=Request.QueryString("amnt" & i) If fname<>"" Then rs.AddNew rs.Fields("ORDER ID") = orderid rs.Fields("ITEMID") = Request.QueryString("Drd1" & i) rs.Fields("QTY") = Request.QueryString("amnt" & i) End If next rs.Update rs.Close Set rs = NothingEnd if %> Link to comment Share on other sites More sharing options...
aspnetguy Posted May 5, 2006 Share Posted May 5, 2006 It means that field name does not exist. Are you sure you spelled it correctly. You shouldn't use spaces in field names. You should modify your DB and rename that field to use (_) instead of a space. Link to comment Share on other sites More sharing options...
Yahweh Posted May 5, 2006 Share Posted May 5, 2006 Open your database and change the field called "NO OF ITEMS" to "NO_OF_ITEMS", and change "ORDER ID" to "ORDER_ID". You can't use spaces in field names.Then change this line of code: rs.Fields("NO OF ITEMS") = totalitmes To this: rs.Fields("NO_OF_ITEMS") = totalitems Change the corresponding rs.Fields("ORDER ID") lines to rs.Fields("ORDER_ID").And here's one more suggestion just to improve performance. Change this line: SQL= "SELECT * FROM ORDER_HEAD;" To this: SQL= "SELECT * FROM ORDER_HEAD WHERE 0=1;" The first select statement gets all the records in all the fields from your table and crams it into a Recordset object, but you aren't using any of those records. With the new SQL statement, you're not returning any records (you don't have to), so you'll have faster execution. You can still add new records just like before, but now you'll just be doing it faster. 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