1: About the record set (Recordset) There are many times you need to use yourself to create an empty record set, and operate the record set. I have the following two categories: A: Plip custom data. (The reason is that the data cannot be obtained according to a SQL, but only one recordset is available) Solution: Create an empty record set, create the record set of the record set, and then populate the data acquisition from a variety of ways: STEP1 : Creating an empty record set set objrs_temp = new adodb.recordset Step2: Insert the field to the recordset and open the record set objrs_temp.fields.Append "FieldName1", Advarchar, 20 objrs_temp.fields.Append "FieldName2", Advarchar, 50 .. .... objrs_temp.open step3: loop inserted data OBJRS_RETURN.ADDNEW OBJRS_TEMP.FIELDS ("FieldName1"). Value = "Value1" ... objrs_return.Update B: Using record sets to sort (most cases are SSDBGRID related) Solution: First create an empty recordset, and store the data in the SSDBGRID in the recordset, use the Sort method of the record set to sort the SORT method, and the data is re-loaded to the SSDBGRID example: Step1: Get the Grid column name And create an empty record set '' 'loop get the Grid field name FieldName1 = GRD.COLUMNS (0) .Name FieldName2 = Grd.columns (1) .name
Set objRS_Temp = New ADODB.RecordSet Step2: Insert Field centralized record and open to the record set objRS_Temp.Fields.Append "FieldName1", adVarChar, 20 objRS_Temp.Fields.Append "FieldName2", adVarChar, 50 ...... objRS_Temp .Open step3: loop inserted data OBJRS_RETURN.ADDNEW OBJRS_TEMP.FIELDS ("FieldName1"). Value = "Value1" ... objrs_return.Update
Step3: Sort by the specific field OBJRS_TEMP.SORT = "FieldName1 DESC" Step4: Cycle Paves the data in the record set to SSDBGRID Notes 1: In STEP2, I started when the field type started, I used ADBSTR (using Unicode encoded) String type), the result record set Sort method is unavailable, and the cause is due to the string for Unicode encoding in the database. Therefore, it will be changed to Advarchar. 20 and 50 behind the type indicate the maximum length of the current field, and should be as consistent with the original data.
Note 2: Use this method in ASP, pay attention to the column type to be enumerated on page (such as const advarchar = 200) attached: DataTyPeenum (Data Type Enumeration Table) http://msdn.microsoft.com/library /default.asp?url=/library/en-us/ado270/htm/mdcstdatatypeenum.aspPrivate Sub Command1_Click () Dim objRS As ADODB.Recordset Dim conn As ADODB.Connection Dim connstring As String Dim strsql As String Dim inti As Integer Dim INTJ AS INTEGER CONNSTRING = "DSN = DB; UID = UID; PWD = PWD" '' 'Get empty record set, please supplement the column according to the situation "' strsql =" SELECT 'AS SYSTEM,' 'AS Process , '' As subprocess, '' as startdatetime from dual "set conn = new adodb.connection '' '" opens the connection, and is set to the client game' '' conn.open conn.CursorLocation = aduseclient set objrs = new adoDB. Recordset '' 'Set to Dynamic Cursor' 'Objrs.open Strsql, Conn, AdoPENDYNAMIC, and ADLOCKBATCHOPTIMISTIC' '' 'The resulting record set is operated' 'objrs.movefirst' '' '' 'among the loops, how much is the designation? Pen record enters record set '' for intj = 0 to 5 '' '' assigning each column '' for inti = 0 to objrs.fields.count - 1 objrs.fields (inti) .Value = "test" & inti next '' '"moves to the next row, and add new line' 'ojrs.movenext objrs.addnewnext' '' deleting the final increased one-line empty Record '' objrs.delete adAffectCurrent '' '' moved to the effective line '' Objrs.movePrevious msgbox objrs.recordcount