Jump to content

jojay

Members
  • Posts

    69
  • Joined

  • Last visited

Posts posted by jojay

  1. i thought that what jojay meant was that he was not getting any result..yeah the syntax is correct. jojay- you may wanna check other parts of the code..

    cname is the field name in the database but I dont want to give any particular letters such '%ja%' because there can be numerous combination in the field "cname".Now, when I use the above code, it result is:
    select * from page1 where cname like '%cname%'

    or what is the best way to search a field name? I have done in the paste and dont remember now.

  2. Hi, Can someone please help with the following syntax:

    sql1 = "Select Cname from page1 where Cname like '%Cname%'"

    Above code isnt working. Cname is a text field and would like to know the syntax for the above sql statement using Like. Thanks.

  3. It's giving you the error on the line with the SQL statement?  That error looks like it should be indicating another line, one where you are trying to access a certain field or something that doesn't exist.  That error says something doesn't exist ('Item cannot be found in the requested collection'), it's not a SQL error from what I can tell.  Are you sure that error is indicating the SQL statement line and not another line?

    Thank you. I fixed the issue. Thank you again for your help.
  4. There's no difference at all, both work just the same. The only difference is the readability of your code (I personally like to see "adOpenStatic" as opposed to "3", its more descriptive).I apologize, but I don't know what you're asking, or what you're trying to get your script to do.

    No problem. I fixed it and it works perfectly. Thankyou. And thanks for explaining the difference.
  5. Hmmm...I haven't the faintest clue why the code isn't working. However, if it's giving you problems, then just go back to executing two seperate queries like you were doing originally.However, make sure when you response.redirect "resultpage.asp?cid=something", you request("CID") on your resultpage.asp to get the passed value.

    Hi,I finally got the querystring working. According to your code, adOpenStatic, adLockoptimistic, was not getting the values from adovb.inc in my case, so I included the const adOpenStatic as 3 and adLockoptimistic as 3 and adUseClient as 3 as declaration and then used them in rs.open, it worked. What is the difference between this:
    rs.open sql1,con,3,3

    and this:

    const adUseClient = 3const adOpenStatic = 3const adLockOptimisitic = 3set connset rsrs.open sql1, adOpenStatic, adLockOptimistic

    Because in my opinion, in the first case, using the const directly without declaring. In the second case, it is declaring and using them. Please correct if I am wrong. Would like to know the difference? My next question, now the querystring is working but still not able to bring all my data to the resultpage.asp. Should I open the connection and using rs, bring the data from the database or just use response.write(fieldname) and pass the data. Confused.

  6. Jojay, theres nothign wrong with the code I wrote, because its a copy/paste from one my own sites. However I made the presumption that you were using ADOVBS.inc (most ASP programmers include that file at the top of their pages by default). Without that file, ASP won't recognize some of the constants like AdUseClient and so on.See 4GuysFromRolla FAQ - ADOVBS.inc, its a good thing to get in the habit of using ADOVBS.inc. Just copy this text file to your root directory (save it as adovbs.inc or adovbs.asp), and add <!--#include file="adovbs.inc"--> to the top of any page that uses ADO, and then the code I wrote above will work.

    Yahweh,I tried and it didnt work. I have a copy of it in my folder but I am assuming that it should be used only when using heavy coding......anyway, that didnt help.here is my error:ADODB.Recordset error '800a0bb9'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. it points to line 39 which is :
    rs.CursorLocation = AdUseClient

    If I comment that line, then the error is going to:

    rs.Open sql1, con, adOpenStatic, adLockOptimisitic

    Now, the error is showing up in result.asp and data is not inserting to the database.I really dont know what is causing my problem not passing the value.

  7. result.asp
    Dim Conn, RS, SQL, LastInsertedIDSet Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.Recordset")Conn.Open your_connection_string	rs.CursorLocation = AdUseClient ' this also gives error so I removed that line	sql1 = "Select * From Your_Table Where 0=1"	rs.Open sql1,conn, 3,3  RS.AddNew  rs("Field1")	= Field1_Value  rs("Field2")	= Field2_Value  rs("Field3")	= Field3_Value  rs("Field4")	= Field4_Value  rs("Field5")	= Field5_Value  RS.Update  LastInsertedID = rs("CID")	RS.closeConn.Closeresponse.redirect "resultpage.asp?CID=" & LastInsertedID

    [resultpage.asp]

    CID = request.querystring("CID")

    I used the above code and I modified some places like the adopenstatic and adlockoptimisitc becoz it is not letting me update and getting an error message such as "Arguement are not same or in conflict to each other"...The above code works fine sending the info into the database but at resultpage.asp, it is not passing still.
  8. Can someone tell how to pass a value from one page to another?I am trying to populate the form in form.asp and send those info to result.asp, dump into the database and response.write that info to the third page which is resultpage.asp. I am able to populate and send to database and it goes to resultpage.asp but it is not response.writing the info.result.asp

    request.form fieldnamesconnection and recordset stringrs.open "Insert into table...."rs.open "Select Top 1 CID from cform Order BY CID Asc"new_id = rs.fields.item("CID").valuers.closecon.closeand set both = nothingresponse.redirect("resultpage.asp?CID = " & New_id)

    resultpage.asp

    CID = request.querystring("new_id")request.form formfieldsresponse.write formfields

    My question is, should I have to create <form></form> and input fields to pass the values to the resultpage.asp. Anyway, I dont want to give a submit button in result.asp to pass the value to resultpage.asp. Any suggestins? Thanks.

  9. OK, try quoting all of the parameters then.  I thought the ssn and job number would be numbers, but just quote everything to be sure:
    Set rs = Server.createobject("Adodb.Recordset")rs.ActiveConnection = "dsn=Candidate"rs.open "Insert into Cform (Cssn, Cjobno) Values('"&Cssn&"','"&Cjobno&"')"rs.open "Select Max(ID) as ID from Cform"new_id = rs.fields.item("ID").value

    I am getting an error when using the select statement:
    rs.open "Select Max(Cid) from Cform" ' getting error when using Max(id) as CID

    error msg:ADODB.Fields error '800a0cc1' Item cannot be found in the collection corresponding to the requested name or ordinal. It looks like it is not recogizing Max(Cid).

  10. Try this
    Set rs = Server.createobject("Adodb.Recordset")rs.ActiveConnection = "dsn=Candidate"rs.open "Insert into Cform (Cssn, Cjobno) Values("&Cssn&","&Cjobno&")"rs.open "Select Max(ID) as ID from Cform"new_id = rs.fields.item("ID").value

    I tried like the above code and also tried like the one below:
    Set con = Server.Createobject("ADODB.Connection")con.open "dsn=Candidate"rs.Activeconnection = conrs.open "Insert into Cform (Cssn, Cjobno) Values("&Cssn&","&Cjobno&")"rs.open "Select Max(ID) as ID from Cform"

    Getting this error for both:Microsoft OLE DB Provider for ODBC Drivers error '80040e14' [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Mc@gmail.com'. ' it is email input type = text

  11. I'm just a little confused by things like this:
    Set rs = con.execute ("Select   Max(CID) from Cform")rs.AddNewrs("Cssn") = Cssnrs("Cjobno") =  Cjobnors.update

    What does it mean logically to execute a select statement to create the recordset, and then start using methods to insert the data?  You can just change the select statement to an insert statement, then you don't need the next 4 lines of code.  You also don't need to set the recordset to the value, an insert query does not return anything.

    Exactly. First I also had the same question but it is not allowing me to send the info to the databse and moreover getting an error such as "Item not found in ......" and if I do a select statement with all the field names it is fine. Anyway, I tried your way:Here is the problem. I am getting an error.
    ADODB.Recordset error '800a0e7d' The connection cannot be used to perform this operation. It is either closed or invalid in this context. result.asp, line 38  ' it is pointing to the insert statement.

    Here is my code:

    Set con = Server.createobject("Adodb.Connection")con.open"dsn=Candidate"Set rs = Server.createobject("Adodb.Recordset")rs.open "Insert into Cform (Cssn, Cjobno Values("&Cssn&","&Cjobno&"))"rs.open ("Select Max(ID) from Cform"), con, 3, 3

  12. I know what you are trying to do, I'm trying to tell you how to do it.  This is the code I gave earlier:
    Set rs = Server.createobject("Adodb.Recordset")rs.ActiveConnection = your_connection_stringrs.open "INSERT INTO Cform ..."rs.open "SELECT MAX(CID) as CID FROM Cform"new_id = rs.fields.item("CID").valuers.close

    This is the code you gave:

    rs.addnewrs.field1rs.field2rs.updatenew_id = rs.fields.item("ID").value

    Why do you have all the rs methods being called?  What are you trying to do with them?  You don't need to use addnew, and you don't need to use update.  And a statement like 'rs.field1' doesn't do anything to begin with.  The reason new_id is blank is because you are doing extra things between the code I pasted and the code you pasted.  Use the code I pasted, write your own SQL insert statement (I don't have the table structure), and watch it work.

    rs.addnewrs.field1rs.field2rs.update

    is another way of inserting data to the database rather update kind. I am more comfortable using addnew method becoz there is no much extra strings to add and it is clean especially sending data to the database. Anyway, will try you way of insert method.

  13. Use the code I gave you, and add your own SQL query there to do the insert.  Don't use the rs.addnew and rs.update and things like that.  You don't need them.

    I am not inserting any data in the last level, only displaying what I just inserted in result.asp.Scenerio:(I am creating a form to input data to send to database. form.asp takes the input of data and sends to result.asp and that page inserts the data and creates a variable to pass to the next page which is resultpage.asp and display the info).
    form.aspformfields....submit button-------------------------result.asprequest.form formfieldsconnectioninsert into the databasecreate variable for id to store the value of id from this page to pass to the next pagerecordset and connection closeresponse.redirect to resultpage.asp-------------------------------resultpage.asprequest.querystring idformfields display

    And the code for the last part is:

    result.aspnew_id = rs.fields.item("ID").valueresultpage.aspID = request.querystring("new_id")

    I guess I have to create another connection and recordset to retrieve the info from database. will try.

  14. I'm not real sure what you're doing with the recordset object.  I think it's just easiest to use SQL statements, instead of using the methods of the recordset object to deal with the database.  So just use queries to do everything:
    Set rs = Server.createobject("Adodb.Recordset")rs.ActiveConnection = your_connection_stringrs.open "INSERT INTO Cform ..."rs.open "SELECT MAX(CID) as CID FROM Cform"new_id = rs.fields.item("CID").valuers.close

    I fixed the sql issue now I have problem passing the value of New_id to the next page, that is resultpage.asp. For some reason, the value is not passing. When I look at my browser URL it shows as:http://mydomain/resultpage.asp?ID=Code for the above:
    rs.addnewrs.field1rs.field2rs.updatenew_id = rs.fields.item("ID").value%><%rs.closeSet rs=nothingcon.closeSet con=nothing%>br /><br /><%response.redirect("resultpage.asp?ID=" & new_id)

    on the resultpage.asp:

    ID = request.querystring("new_id")

  15. I don't really like the way ASP interacts with databases, but this is how I do it:
    var week_con = Server.CreateObject("ADODB.recordset");week_con.ActiveConnection = ts_dbcon_str;week_con.open("SELECT * FROM week WHERE startDate=" + sDate.valueOf() + " AND endDate=" + eDate.valueOf());if (!week_con.eof){  ...}week_con.close();

    I only use the recordset object, not a connection (despite the name).  I'm not sure what code you are working with now or what problems you are having.  If you want help paste the code you are using.  For the SQL statement, just use one query to get the new ID, and a second query to get all of the information about that ID.

    Sorry and thank you for your help. I didnt understand in the first place regarding the connection and recordset object. I am working on the code to refresh the page without getting the data to the database. And your suggestion seemed good and so I started working in your direction. Now, it seems good but getting error when using the sql statement. Here is my code:result.asp
    <%Set con = Server.createobject("Adodb.Connection")con.open"dsn=Candidate"Set rs = Server.createobject("Adodb.Recordset")Set rs = con.execute ("Select   Max(CID) from Cform")rs.AddNewrs("Cssn") = Cssnrs("Cjobno") =  Cjobnors.updatenew_id = rs.fields.item("CID").value%><%rs.closeSet rs=nothingcon.closeSet con=nothing%>response.redirect("resultpage.asp?Cid=" + new_id)

    So far so good. But I am not able to get to the sql statement your way. Any help would be greatful. Thanks again.

  16. I am having problem with this code. When I use as this:

    rs.open "Select Max(ID) as myid from cform", con, 3, 3

    It is not recognizing the other fields in the database and I am getting an error such as "Item not to be found for the requested........."So, I changed the Select statement using all the fields such as:

    "Select Max(CID), Cssn, ......from cform"

    Now, I am getting this error message:Microsoft OLE DB Provider for ODBC Drivers error '80040e14' [Microsoft][ODBC Microsoft Access Driver] You tried to execute a query that does not include the specified expression 'Cssn' as part of an aggregate function. I understand since we are using the Max function, it is showing up that error. What is the round about to do this? Thanks for the help.

  17. I am still having problems with my code. I am getting the following error:Microsoft OLE DB Provider for ODBC Drivers error '80040e10' [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. I have few questions:Why do you have use :

    con.open "Select Max(ID) as myid from cform"

    should it be :

    rs.open "Select Max(ID) as myid from cform", con, 3, 3

    because I am already opening the con.open "dsn=candidate"the error points at:

    new_id = con.fields.item("myid").value

    after the above code, giving rs.addnew.....so on...

  18. Directly after you insert everything into the database (as in the statement right after the SQL query), you need to get the highest ID number:
    sqlcon.open("SELECT MAX(id) AS id FROM table");new_id = sqlcon.fields.item("id").value;...response.redirect("processpage.asp?id=" + new_id);processpage.asp:id = request.querystring("id");

    I just want to make sure if I am doing it right: here is my modified code:
    Form.aspID field as hiddenother formfields....Submit button------result.aspformfields = request.form("formfields")Set con = server.createobject("ADODB.Connection")con.open "dsn=mydsn"Set rs = server.createobject("ADODB.Recordset")rs.open "select * from tablename where 0=1",3,3addnew method to insert to databasers.updatecon.open("Select Max(id) as myid from tablename");new_id = con.fields.item("id").value [COLOR=red]'I dont understand this line...what is con.fields.item...is the fieldname from the table...[/COLOR]connection.closerecordset.closeresponse.redirect("resultpage.asp?id=" + new_id);-------resultpage.aspCID = Request.querystring("CID")response.write("formfields")Print command to print.

    Thank you for your help.

  19. Hi,I tried to work this around and I am almost there but with little problem. What I did is, is to keep the form.asp and direct the result to result.asp. In result.asp, i am giving the response.redirect to resultpage.asp and also included the <input type="hidden" name="ID">. In resultpage.asp, i am trying to get the results from form.asp through the hidden ID. In resultpage.asp, the codes are:
    ID = Request.form("ID")<input type="hidden" name="ID" value="<%response.write("ID")%>">then table with form fields as response.write(request.form("fieldname"))

    As you can see, I havent given connection to the database since I am just extracting the result to this page through response.write. But I am getting an error such as below:"object required".what does it mean? Do  I need connection in this page? thanks.

    I understand what it means. How will I get the ID from previous page. This is my scenerio:
    Form.aspID field as hiddenother formfields....Submit button------result.aspformfields = request.form("formfields")Set connection..Set Recordset...addnew method to insert to database<input type="hidden" name="CID" value="<%=rs("CID")%>">connection.closerecordset.closeresponse.redirect("resultpage.asp")-------resultpage.aspCID = Request.Form("CID")response.write("formfields")Print command to print.

    Now, since I have given autonumber as datatype for CID, each time when I sent the data to the database, the autonumber increments. How will I get the CID from the database to show up in resultpage.asp. Should I open again the connection and retreive the CID? Please help.

  20. Hi,I tried to work this around and I am almost there but with little problem. What I did is, is to keep the form.asp and direct the result to result.asp. In result.asp, i am giving the response.redirect to resultpage.asp and also included the <input type="hidden" name="ID">. In resultpage.asp, i am trying to get the results from form.asp through the hidden ID. In resultpage.asp, the codes are:

    ID = Request.form("ID")<input type="hidden" name="ID" value="<%response.write("ID")%>">then table with form fields as response.write(request.form("fieldname"))

    As you can see, I havent given connection to the database since I am just extracting the result to this page through response.write. But I am getting an error such as below:"object required".what does it mean? Do I need connection in this page? thanks.

  21. At the end.  Here is my uber-detailed schematic of process.asp:
    <get responses from POST> username = request.form("username")<validate responses> user entered a string for a number? bad user! smack them to the ground!<insert into database><get id for new data>response.redirect("thanks.asp?id=" + new_id)

    Since you will probably want to validate the variables, it might be a good idea to have the form page do all the processing also.  So, the form page would show the form, and would also do the above, get all the data, validate it, insert into the database, and redirect.  You can go one step further, and also have the form page redirect back to itself.  That way you only use 1 page (although the code might be a little confusing).  It doesn't matter which page you redirect to, as long as a redirect happens.  That way they refresh the redirected page (which didn't do any processing) instead of the page that inserted into the db.

    Thank you very much. I wouldnt have had a better explanation. But one thing I dont understand - <get id for new data>. Is it like this: <input type="hidden" name="id"> to redirect to same page or to different page?
  22. It's probably best to have form.asp submit to process.asp, and have process put everything in the database and then redirect to something like result.asp, and send result the ID number of the record that was just inserted in the database.  That way, process can look up the info from the database and display it.

    Sounds good. But can you tell at which point will I response.redirect the result of ID from process.asp to result.asp. That is, should it come somewhere in the beginning or at end.
  23. You can always insert a database processing page.form.asp   fill out the form and submitprocess.asp  insert into the database, response.redirect to result.asp, or back to form.aspSince the process page does a response.redirect, they will be refreshing the redirected page, not the page that did the processing.

    That is how it is now.I have form.asp and submit. That information is going to resultpage.asp in which the processing is taking place using Addnew method. But I dont have response.direct in the result page to the same page. If i do response.redirect("resultpage.asp"), will the content remain in the page? Because on the resultpage.asp, I am also response.write all the info which was entered on form.asp, so if I want to print the info, can use the print command.
×
×
  • Create New...