Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: looping in asp??

  1. #1
    keroed1 Guest

    Default looping in asp??

    i am trying to do a simple loop in my asp i am reading some data from a database i want to loop through all of the values i get using my select statement and display it on the screen cyrrently i have

    <% Response.write oRecordset("Carrier")%>

    but this only writes the first result only how do i loop?? and keep on writing the datato the screen??

  2. #2
    keroed1 Guest

    Default

    guys where following around and i found out how to do this...........but i wold love a link for some one two .asp code samples

    but a prob is when i loop through i get the data been displayed in the following format on the screen
    ::::::::::::::::::;
    Cable And Wireless Land LinesCable And Wireless Land LinesDigicelDigicelbmobilebmobileMiphoneMiphoneInv alidInvalidInternationalInternational
    :::::::::::::::

    is it possible for to put lines in betweent the valuesi rterieve
    Last edited by keroed1; Jun 5, 2006 at 09:36 PM.

  3. #3
    Join Date
    Apr 2003
    Posts
    13,270
    Rep Power
    35

    Default

    Code:
    <% Response.write oRecordset("Carrier") & vbNewLine %>
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  4. #4
    Join Date
    Feb 2005
    Posts
    73
    Rep Power
    0

    Default

    another way to solve this problem and many others is by first using google.
    For this problem try (asp loop vbscript)

    The first page I looked at had three or more ways to loop. If you try (asp loop vbscript end recordset) or (asp loop "loop through recordset") You get even more specific information. With a little bit of looking you will start noticing that EOF is end of file. So if you didn't aready find your answer try (asp vbscript loop eof)

    this is on the first page. Though I didn't include all the code, but the rest you should already have.

    Code:
    If not RS.eof then
      RS.movefirst
      Do
        Response.write "Here is some Data " & RS("Field")
        Rs.movenext
      Loop until RS.eof
    End if
    Please look before you ask. If you can't find it then feel free to ask.

    Oh and that most likely would have shown you how to insert a newline.

    There are many ways to do this. I usually end my ASP code and use <br> as the example that I found on google did.

    Please also try and balance how many questions you ask with how many questions you answer. I don't know that you don't already, so if you do, great.
    Last edited by Arch_Angel; Jun 6, 2006 at 01:45 PM. Reason: merged posts

  5. #5
    Join Date
    Apr 2003
    Posts
    13,270
    Rep Power
    35

    Default

    Well said Offroad.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  6. #6
    keroed1 Guest

    Default

    i toke your example and i researched up on how to update a database using asp and i am trying some the code they said i should use but i keep on getting an error

    Code:
    dim sCarrier,sTime,sCPMS,sCost
    sCost=request.Form("txtCost")
    sCPMS=request.Form("selCPMS")
    sTime=request.Form("selTime")
    sCarrier=request.Form("selCarrier")
    
    Set oCmd = Server.CreateObject("ADODB.Command")
           Set oCmd.ActiveConnection = oConnection
           sSql = "UPDATE tblRates SET Cost = " & 12 & " WHERE TimeType = " & "Peak" & ";"
           oCmd.CommandText = sSql
           oCmd.CommandType = adCmdText
           oCmd.Execute
           Set oCmd = Nothing
    but i keep on getting this error
    ADODB.Command (0x800A0BB9)
    Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
    /CallAccounting/members/admin/rates.asp, line 140

    # Browser Type:
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7

    # Page:
    POST 97 bytes to /CallAccounting/members/admin/rates.asp

    # POST Data:
    selCarrier=Cable+And+Wireless+Land+Lines&selTime=P eak&selCPMS=M&txtCost=10.25&Submit=Update+Rates
    i am not sure what i am doing wrong
    is that i need to parse the values i get because some of the value sin the database i am trying to update is currency and text

  7. #7
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    I don't think you use ";" with SQL and use extra caution with update statements cause they can clean you entire database if the where clause it not set to what you want, test is out first with some select clause instead of update
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  8. #8
    keroed1 Guest

    Default

    its an access database, should the ; still be there???

    i removed the ; and i dont get the error now it looks like this

    Set oConnection=Server.CreateObject("ADODB.Connection" )
    Set oCmd = Server.CreateObject("ADODB.Command")
    Set oCmd.ActiveConnection = oConnection
    sSqlString = "UPDATE tblRates SET Cost = '" & sCost & "' WHERE TimeType = '" & sCPMS &"'"
    oCmd.CommandText = sSqlString
    oCmd.CommandType = 1
    oCmd.Execute
    Set oCmd = Nothing

    but when i run it even though i dont get the error the tables are'nt updated

    got any pointers for me?
    Last edited by keroed1; Jun 6, 2006 at 08:32 PM.

  9. #9
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    My bad. The semicolon works fine, the problem was with the type for Peak or how it was written with quotes. I was trying to test the semi-colon in a batch of two SELECT statements, instead of GO, to see it that works but batch was not supported by the Jet provider.

    I am testings a select query on a Access database at the moment, and it is not working, and I am suspicious of the provider with the command object
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  10. #10
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    Rahtid! It was working all the time but I was testing it with an unsuppoted property recordset.record count, as soon as I used a visual of the recordset, recordset(0), everything was there.

    Here is my test file. (I recently found out (or remembered) about Windows Scripting so I did it as a .js file that you can right click an run if you have Windows Script Host.)
    Code:
    //file : testsemicolon.js
    
    //ignore WScript
    var WshShell = WScript.CreateObject("WScript.Shell");
    
    
    var strDBPath = "J:\\DBs\\Office10\\Samples\\Northwind[edit].mdb";
    var strSQL = "SELECT FirstName FROM Employees WHERE EmployeeID = 1;"
    			  //+ " SELECT FirstName FROM Employees WHERE EmployeeID = 2";
    var strUPDATE = "UPDATE Employees SET FirstName = 'nAncY' WHERE EmployeeID = 1;"
    
    var conn = new ActiveXObject("ADODB.Connection");
    var intRecords = 0;
    //var conn = WScript.CreateObject("ADODB.Connection")
    
    var command = new ActiveXObject("ADODB.Command");
    //var command = WScript.CreateObject("ADODB.Command")
    var rsAns = new ActiveXObject("ADODB.Recordset");
    
    
    conn.Provider="Microsoft.Jet.OLEDB.4.0";
    conn.Open(strDBPath);
    if(conn.State == 1)//adStateOpen
    {
    	WshShell.Popup("Connection opened\n");
    	switch(conn.Mode)
    	{
    		case 1://adModeRead
    		WshShell.Popup("Opened with adModeRead\n");break;
    		case 2://adModeWrite
    		WshShell.Popup("Opened with adModeWrite\n");break;
    		case 3://adModeReadWrite
    		WshShell.Popup("Opened with adModeReadWrite\n");break;
    		default:
    		WshShell.Popup("Opened with mode = " + conn.Mode + "\n");break;
    	}
    }
    else
    	WshShell.Popup("Error opening\n");
    
    
    command.ActiveConnection = conn;
    command.CommandType = 1;//adCmdText
    //command.CommandText = strSQL;
    command.CommandText = strUPDATE;
    
    rsAns = command.Execute(intRecords);	//works
    //rsAns = conn.Execute(command.CommandText, intRecords);	//works
    //intRecords = rsAns.Open(command);	//works
    
    //WshShell.Popup(rsAns(0)); //This is a good test line for select
    WshShell.Popup(intRecords + " were selected\n");  //This is a bad test line
    //WshShell.Popup("Recordset count = " + rsAns.RecordCount);  //This is a bad test line with Jet provider for select
    /*
    rsAns.NextRecordset(intRecords);	//NextRecordset unsupported in Jet
    WshShell.Popup(intRecords + " were selected\n");
    WshShell.Popup("Next Recordset count = " + rsAns.RecordCount);
    */
    
    conn.Close();
    
    WScript.Quit(0);
    
    
    
    
    
    
    
    
    
    //ignore below is for crosswire reference
    var ExcelApp = new ActiveXObject("Excel.Application");
    var ExcelSheet = new ActiveXObject("Excel.Sheet");
    // Make Excel visible through the Application object.
    ExcelSheet.Application.Visible = true;
    // Place some text in the first cell of the sheet.
    ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";
    // Save the sheet.
    //ExcelSheet.SaveAs("C:\\TEST.XLS");
    // Close Excel with the Quit method on the Application object.
    
    WScript.Sleep(3000);
    
    WshShell.Popup("Click to close now\n");
    ExcelSheet.Application.Quit();
    It does not look like you are using a Relational database that would cause any error in update which probably is displayed. So I think that your SQL statement is buggy and not a syntax problem for Microsoft Jet SQL dialect. If the column types are strings in access then maybe the case of a letter is wrong. Not sure if it is case sensitive, can check that later
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •