Ga naar inhoud

[ASP] record nr. zoveel selecteren uit een tabel


anoniem

Aanbevolen berichten

Dit is de snelle methode :wink: Het komt er op neer dat je simpel aangeeft welk record je wilt zien: RecordSet.Move 7 Voorbeeld van de methode Move (VBScript) In dit voorbeeld wordt de methode Move gebruikt om de recordaanwijzer te verplaatsen volgens instructies van de gebruiker. Gebruik het volgende voorbeeld in een Active Server Page (ASP). Om dit volledig werkende voorbeeld te kunnen weergeven, moet de gegevensbron AdvWorks.mdb (die samen met de SDK wordt geïnstalleerd) zich bevinden op C:mssdksamplesdataaccessrds. Dit is een Microsoft Access-databasebestand. Gebruik Zoeken om het bestand Adovbs.inc te vinden en plaats het in de map die u wilt gebruiken. Knip en plak de volgende code naar Kladblok of een andere teksteditor en sla het op onder de naam Move.asp. Het resultaat kunt u in elke browser bekijken. Probeer een letter of niet-geheel getal in te voeren om te zien hoe de foutafhandeling werkt. [code:1:75924d3d65] <%@ Language=VBScript %> <!-- #Include file="ADOVBS.INC" --> <HTML> <HEAD> <TITLE>ADO Move Methods</TITLE> <STYLE> <!-- BODY { font-family: "MS SANS SERIF",sans-serif; } .thead1 { background-color: #008080; font-family: 'Arial Narrow','Arial',sans-serif; font-size: x-small; color: white; } .tbody { text-align: center; background-color: #f7efde; font-family: 'Arial Narrow','Arial',sans-serif; font-size: x-small; } --> </STYLE> </HEAD> <BODY> <H3>ADO Move Methods</H3> <% src = "C:mssdksamplesdataaccessrdsadvworks.mdb" sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & src 'Create and Open Connection Object Set OBJdbConn = Server.CreateObject("ADODB.Connection") OBJdbConn.Open sConnStr 'Maak en open Recordset-object Set RsCustomerList = Server.CreateObject("ADODB.Recordset") RsCustomerList.ActiveConnection = OBJdbConn RsCustomerList.CursorType = adOpenKeyset RsCustomerList.LockType = adLockOptimistic RsCustomerList.Source = "Customers" RsCustomerList.Open 'Controleer het aantal verplaatsingen door de gebruiker in deze sessie. 'Verhoog met aantal in formulier. Session("Clicks") = Session("Clicks") + Request.Form("MoveAmount") Clicks = Session("Clicks") ' Ga naar laatst bekende recordsetpositie plus het aantal doorgegeven ' door methode Form Post. RsCustomerList.Move CInt(Clicks) 'Foutafhandeling If RsCustomerList.EOF Then Session("Clicks") = RsCustomerList.RecordCount Response.Write "This is the Last Record" RsCustomerList.MoveLast Else If RsCustomerList.BOF Then Session("Clicks") = 1 RsCustomerList.MoveFirst Response.Write "This is the First Record" End If End If %> <H3>Current Record Number is <BR> <% If Session("Clicks") = 0 Then Session("Clicks") = 1 End If Response.Write(Session("Clicks") )%> of <%=RsCustomerList.RecordCount%></H3> <HR> <TABLE COLSPAN=8 CELLPADDING=5 BORDER=0> <!-- BEGIN rij met kolomkop voor tabel Customers--> <TR CLASS=thead1> <TD>Company Name</TD> <TD>Contact Name</TD> <TD>Phone Number</TD> <TD>City</TD> <TD>State/Province</TD> </TR> <!--Geef ADO-gegevens uit tabel Customers weer--> <TR CLASS=tbody> <TD> <%= RSCustomerList("CompanyName")%> </TD> <TD> <%= RScustomerList("ContactLastName") & ", " %> <%= RScustomerList("ContactFirstName") %> </TD> <TD> <%= RScustomerList("PhoneNumber")%> </TD> <TD> <%= RScustomerList("City")%> </TD> <TD> <%= RScustomerList("StateOrProvince")%> </TD> </TR> </TABLE> <HR> <Input Type=Button Name=cmdDown Value="< "> <Input Type=Button Name=cmdUp Value=" >"> <H5>Click Direction Arrows for Previous or Next Record <BR> Click Move Amount to use Move Method Enter Number of Records to Move + or - </H5> <TABLE> <FORM Method = Post Action="Move.asp" Name=Form> <TR> <TD><Input Type="Button" Name=Move Value="Move Amount "></TD> <TD></TD> <TD><Input Type="Text" Size="4" Name="MoveAmount" Value=0></TD> <TR> </FORM> </TABLE> </BODY> <Script Language = "VBScript"> Sub Move_OnClick ' Controleer of ingevoerde waarde een geheel getal is. If IsNumeric(Document.Form.MoveAmount.Value)Then Document.Form.MoveAmount.Value = CInt(Document.Form.MoveAmount.Value) Document.Form.Submit Else MsgBox "You Must Enter a Number", ,"ADO-ASP Example" Document.Form.MoveAmount.Value = 0 End If End Sub Sub cmdDown_OnClick Document.Form.MoveAmount.Value = -1 Document.Form.Submit End Sub Sub cmdUp_OnClick Document.Form.MoveAmount.Value = 1 Document.Form.Submit End Sub </Script> [/code:1:75924d3d65] [ Dit Bericht is bewerkt door: Wiep Corbier op 2002-02-21 20:20 ]
Link naar reactie
allen bedankt voor de reacties maar het is niet helemaal wat ik bedoelde.... inmiddels ben ik al wat verder gevorderd en heb weer een nieuw probleem Waar ik mee bezig ben, is het verspreiden van zoekresultaten over meerdere pagina's (ASP en Access)... zie code: [code:1:05cf509b5d] <%@ Language=VBScript %> <% Option Explicit %> <!--#include file = "../Include/adovbs.inc"--> <!--#include file = "../Include/constanten.inc"--> <% Dim rsData, strSQL, dbConn Dim longEmployeeID, strDateBegin, strDateEnd Dim strDatabaseLocation Dim longPageSize, longCurrPage, longPageCount strDatabaseLocation = Server.MapPath("../CMDB.mdb") Set dbConn = Server.CreateObject("ADODB.Connection") dbConn.ConnectionString = _ "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Persist Security Info=False;Data Source=" _ & strDatabaseLocation dbConn.Open longEmployeeID = Request.QueryString("ID") strDateBegin = Request.QueryString("strDateBegin") strDateEnd = Request.QueryString("strDateEnd") longPageSize = 5 Set rsData = Server.CreateObject("ADODB.Recordset") rsData.CursorLocation = 3 rsData.PageSize = longPageSize strSQL = "SELECT tblIncident.IncidentID, tblIncident.Location, " _ & "tblIncident.Department, tblEmployee.Surname, " _ & "tblEmployee.Middleinitials, " _ & "tblEmployee.Lastname, tblIncident.CallDateTime, " _ & "tblIncident.IncidentDateTime, tblIncident.LongDescription, " _ & "tblIncident.SolutionDescription, tblIncident.ProgressDescription, " _ & "tblIncident.ShortDescription, tblCategory.Category, " _ & "tblPriority.Priority, tblDesktop.ConfigID, " _ & "tblIncident.ClosedDateTime FROM tblPriority " _ & "INNER JOIN ((tblDesktop INNER JOIN " _ & "tblEmployee ON tblDesktop.ConfigID = " _ & "tblEmployee.ConfigID) INNER JOIN " _ & "(tblCategory INNER JOIN tblIncident " _ & "ON tblCategory.CategoryID = tblIncident.CategoryID) " _ & "ON tblEmployee.EmployeeID = tblIncident.EmployeeID) " _ & "ON tblPriority.PriotityID = tblIncident.PriotityID " _ & "WHERE tblIncident.EmployeeID=" & longEmployeeID _ & " AND tblIncident.Active=False " _ & "AND tblIncident.ClosedDateTime>=" & strDateBegin _ & " AND tblIncident.ClosedDateTime<=" & strDateEnd _ & " ORDER BY tblIncident.IncidentDateTime;" rsData.Open dbConn, strSQL, adOpenStatic, adLockReadOnly, adCmdText longPageCount = rsData.PageCount If 1 > longCurrPage Then longCurrPage = 1 End If If longCurrPage > longPageCount Then longCurrPage = longPageCount End If rsData.AbsolutePage = CInt(longCurrPage) %> <html><head></head> <link rel='STYLESHEET' type='text/css' href='../stylesheet/Style.css'> <body><p> <% Do While rsData.AbsolutePage = longCurrPage AND Not rsData.EOF %> <table cellspacing="3"> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">IncidentID: </td> <td align="left"><%= rsData("IncidentID") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Korte omschrijving: </td> <td align="left"><%= rsData("ShortDescription") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Lange omschrijving: </td> <td align="left"><%= rsData("LongDescription") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Afdeling: </td> <td align="left"><%= rsData("Department") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Tijdstip melding: </td> <td align="left"><%= rsData("CallDateTime") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Tijdstip incident: </td> <td align="left"><%= rsData("IncidentDateTime") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Tijdstip afsluiten: </td> <td align="left"><%= rsData("ClosedDateTime") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Locatie: </td> <td align="left"><%= rsData("Location") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Categorie: </td> <td align="left"><%= rsData("Category") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Prioriteit: </td> <td align="left"><%= rsData("Priority") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">ConfigID: </td> <td align="left"><%= rsData("ConfigID") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Voortgangsomschrijving: </td> <td align="left"><%= rsData("ProgressDescription") %></td> </tr> <tr> <td align="left" valign="top" bgcolor="#C9EDD8">Oplossingsomschrijving: </td> <td align="left"><%= rsData("SolutionDescription") %></td> </tr> <tr> <td colspan="2"><hr style="color:#C9EDD8"></td> </tr> </table><br> <% rsData.MoveNext Loop If longCurrPage <> 1 Then Response.Write "<a href='EmployeeReportDetails.asp?ID=" & rsIncidents("EmployeeID") & "&Page=" & (longCurrPage - 1) & "&strDateBegin=" & strDateBeginASP & "&strDateEnd=" & strDateEndASP & "'>Previous</a>" End If If longCurrPage < longPageCount Then Response.Write "<a href='EmployeeReportDetails.asp?ID=" & rsIncidents("EmployeeID") & "&Page=" & (longCurrPage + 1) & "&strDateBegin=" & strDateBeginASP & "&strDateEnd=" & strDateEndASP & "'>Next</a>" End If rsData.Close Set rsData = Nothing dbConn.Close Set dbConn = Nothing %> </p> </body> </html> [/code:1:05cf509b5d] en nou krijg ik elke keer de foutmelding:[i:05cf509b5d] ADODB.Recordset error '800a0bb9' The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another. /BSL/Reports/EmployeeReportDetails.asp, line 51 [/i:05cf509b5d] en dat is de regel onder mijn SQL-definitie... Nou heeft het waarschijnlijk iets met de cursortypes te maken, maar de door mij gebruikte cursortypes staan ook op site waar ik het script vandaan heb. Heb zelf ook al andere combinaties van cursortypes geprobeerd, maar tot nu toe tevergeefs. Iemand een suggestie hierover? thx Matthijn [ Dit Bericht is bewerkt door: matthijn99 op 2002-02-22 15:23 ]
Link naar reactie
[quote:08f50a9c1f] Op 22-02-2002 23:59, schreef Annie: sql en connectie omgedraaid, moet zijn: rsData.Open strSQL, dbConn, adOpenStatic, adLockReadOnly, adCmdText [/quote:08f50a9c1f] sjongejonge ja wat dom die regel heb ik onderhand al 1000x gebruikt en dan gaat het nu fout?!?!? ik ga het maandag gelijk proberen op mijn werk, bedankt Annie en die andere tip over GetRows zal ik ook naar gaan kijken
Link naar reactie
ik heb nu de fout eruit gehaald die Annie had aangegeven, maar nu krijg ik de volgende foutmelding: [b:6dbc57bf22][i:6dbc57bf22]ADODB.Recordset error '800a0bb9' The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another. /BSL/Reports/EmployeeReportDetails.asp, line 67[/i:6dbc57bf22][/b:6dbc57bf22] hieronder nogmaals (een gedeelte van) de code: [code:1:6dbc57bf22]<%@ Language=VBScript %> <% Option Explicit %> <!--#include file = "../Include/adovbs.inc"--> <!--#include file = "../Include/constanten.inc"--> <% Dim rsData, strSQL, dbConn Dim longEmployeeID, strDateBegin, strDateEnd Dim strDatabaseLocation Dim longPageSize, longCurrPage, longPageCount strDatabaseLocation = Server.MapPath("../CMDB.mdb") Set dbConn = Server.CreateObject("ADODB.Connection") dbConn.ConnectionString = _ "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Persist Security Info=False;Data Source=" _ & strDatabaseLocation dbConn.Open longEmployeeID = Request.QueryString("ID") strDateBegin = Request.QueryString("strDateBegin") strDateEnd = Request.QueryString("strDateEnd") longPageSize = 5 If(Request.QueryString("Page")) = "" Then longCurrPage = 1 Else longCurrPage = CInt(Request.QueryString("Page")) End If Set rsData = Server.CreateObject("ADODB.Recordset") rsData.CursorLocation = 3 rsData.PageSize = longPageSize strSQL = "SELECT tblIncident.IncidentID, tblIncident.Location, " _ & "tblIncident.Department, tblEmployee.Surname, " _ & "tblEmployee.Middleinitials, " _ & "tblEmployee.Lastname, tblIncident.CallDateTime, " _ & "tblIncident.IncidentDateTime, tblIncident.LongDescription, " _ & "tblIncident.SolutionDescription, tblIncident.ProgressDescription, " _ & "tblIncident.ShortDescription, tblCategory.Category, " _ & "tblPriority.Priority, tblDesktop.ConfigID, " _ & "tblIncident.ClosedDateTime FROM tblPriority " _ & "INNER JOIN ((tblDesktop INNER JOIN " _ & "tblEmployee ON tblDesktop.ConfigID = " _ & "tblEmployee.ConfigID) INNER JOIN " _ & "(tblCategory INNER JOIN tblIncident " _ & "ON tblCategory.CategoryID = tblIncident.CategoryID) " _ & "ON tblEmployee.EmployeeID = tblIncident.EmployeeID) " _ & "ON tblPriority.PriotityID = tblIncident.PriotityID " _ & "WHERE tblIncident.EmployeeID=" & longEmployeeID _ & " AND tblIncident.Active=False " _ & "AND tblIncident.ClosedDateTime>=" & strDateBegin _ & " AND tblIncident.ClosedDateTime<=" & strDateEnd _ & " ORDER BY tblIncident.IncidentDateTime;" rsData.Open strSQL, dbConn, adOpenDynamic, adLockPessimistic, adCmdText longPageCount = rsData.PageCount If 1 > longCurrPage Then longCurrPage = 1 End If If longCurrPage > longPageCount Then longCurrPage = longPageCount End If rsData.AbsolutePage = longCurrPage [/code:1:6dbc57bf22] de genoemde foutmelding heeft betrekking op de laatste regel in de code ook hier heb ik naar gezocht maar ik zie niet wat het probleem kan zijn, aangezien deze regel in alle voorbeelden gebruikt wordt die ik gevonden heb... iemand nog een suggestie? (Annie misschien?) gr Matthijn
Link naar reactie
nou ik begrijp er niet veel meer van ik heb in Access een query gemaakt waarvan de SQL er zo uitziet: [code:1:bd01acd8f3]SELECT tblIncident.IncidentID, tblIncident.Location, tblIncident.Department, tblIncident.CallDateTime, tblIncident.IncidentDateTime, tblIncident.ClosedDateTime, tblIncident.LongDescription, tblIncident.SolutionDescription, tblIncident.ConfigID, tblIncident.ProgressDescription, tblIncident.ShortDescription, tblPriority.Priority, tblCategory.Category, tblEmployee.Surname, tblEmployee.Lastname, tblEmployee.Middleinitials FROM tblPriority INNER JOIN (tblEmployee INNER JOIN (tblCategory INNER JOIN tblIncident ON tblCategory.CategoryID = tblIncident.CategoryID) ON tblEmployee.EmployeeID = tblIncident.EmployeeID) ON tblPriority.PriotityID = tblIncident.PriotityID WHERE (((tblIncident.ClosedDateTime)>[strDateBegin] And (tblIncident.ClosedDateTime)<[strDateEnd]) AND ((tblIncident.Active)=False) AND ((tblIncident.EmployeeID)=[longEmployeeID])); [/code:1:bd01acd8f3] deze query kan ik uitvoeren, waarbij de waardes tussen '[]' variabelen zijn die ik dan invoer, en dan krijg ik keurig de resultaten die ik verwacht. Zet ik vervolgens die SQL in een ASP-pagina, dan ziet dat er zo uit: [code:1:bd01acd8f3] strSQL = "SELECT tblIncident.IncidentID, tblIncident.Location, " _ & "tblIncident.Department, tblIncident.CallDateTime, " _ & "tblIncident.IncidentDateTime, tblIncident.ClosedDateTime, " _ & "tblIncident.LongDescription, tblIncident.SolutionDescription, " _ & "tblIncident.ConfigID, tblIncident.ProgressDescription, " _ & "tblIncident.ShortDescription, tblPriority.Priority, " _ & "tblCategory.Category, tblEmployee.Surname, " _ & "tblEmployee.Lastname, tblEmployee.Middleinitials FROM tblPriority " _ & "INNER JOIN (tblEmployee INNER JOIN (tblCategory INNER JOIN " _ & "tblIncident ON tblCategory.CategoryID = tblIncident.CategoryID) " _ & "ON tblEmployee.EmployeeID = tblIncident.EmployeeID) " _ & "ON tblPriority.PriotityID = tblIncident.PriotityID " _ & "WHERE ((tblIncident.ClosedDateTime>" & strDateBegin & " AND tblIncident.ClosedDateTime<" & strDateEnd _ & ") AND tblIncident.Active=False AND tblIncident.EmployeeID=" & longEmployeeID _ & ") ORDER BY tblIncident.IncidentDateTime;" rsData.Open strSQL, dbConn, adOpenStatic, adLockReadOnly, adCmdText[/code:1:bd01acd8f3] laat ik deze ASPpagina draaien (dus de query uitvoeren), is de recordset leeg. Dan zou er dus iets mis kunnen zijn met de variabelen die ik in de query invoer, maar ook die zijn goed, als ik die even 'response.write' hebben ze de waarde die ze moeten hebben ????????? *nu het echt niet meer weet* :???: [ Dit Bericht is bewerkt door: matthijn99 op 2002-02-25 13:25 ]
Link naar reactie

Om een reactie te plaatsen, moet je eerst inloggen

Gast
Reageer op dit topic

×   Geplakt als verrijkte tekst.   Herstel opmaak

  Er zijn maximaal 75 emoji toegestaan.

×   Je link werd automatisch ingevoegd.   Tonen als normale link

×   Je vorige inhoud werd hersteld.   Leeg de tekstverwerker

×   Je kunt afbeeldingen niet direct plakken. Upload of voeg afbeeldingen vanaf een URL in

  • Populaire leden

    Er is nog niemand die deze week reputatie heeft ontvangen.

  • Leden

    Geen leden om te tonen

×
×
  • Nieuwe aanmaken...