1 How do I display the data in the database in the DataGrid list? Private Sub showdata1 (SQLSTR AS STRING) DIM CN As New Adodb.ConnectionDim CMD As New AdoDb.commanddim Rs1 As New AdoDb.RecordSetdim DsRows AS Integer Screen.MousePointer = 11
ON Error Resme nextcn.cursorLocation = aduseclient
Cn.open constrset cmd.activeConnection = CN
Cmd.commandtext = SQLSTRRS1.OPEN CMD, AdopenKeyset, AdlockOptimisticDim J AS Integeron Error Goto Errmess
DSROWS = rs1.recordcount 1Grid1.cols = rs1.fields.countgrid1.colwidth (Grid1.cols - 1) = 1 'column width is 1, do not let users see Grid1.Row = 0 for i = 0 to rs1.fields .Count - 1 'minus the last column Grid1.col = I Grid1.text = rs1.fields (i) .Name Next I Grid1.Rows = rs1.RecordCount 1 Grid1.cols = rs1.fields.count i = 1 DO While Not Rs1.eof
For J = 0 to RS1.Fields.count - 1 IF j = rs1.fields.count - 1 Then Grid1.textMatrix (i, j) = getobjid (CSTR (RS1 (0))) Else if not isnull (RS1 (J) ) .Value) Then Grid1.textMatrix (i, j) = CSTR (RS1 (j)) end if endiff
RS1.MOVENEXT I = i 1 loop
RS1.Close set RS1 = Nothing cn.close set cn = Nothing statusbar1.panels.Item (2) .text = "There is" " str (dsRows) " "strum record" Statusbar1.Panels.Item 1) .Text = "Intersection" screen.mousepointer = 1exit suberrmess: msgbox ("Query error, please contact the system administrator!") Screen.MousePointer = 1 set = Nothing rs1.close cn.close set cn = HowNagend Sub2 gives DataGrid page? '--------- Page Display Process --------------------- Public Function EveryrowDisplay (SQL AS String, Formatstr AS String, Rowsum As Integer, colSum As Integer, StartP As Integer) As StringfMainForm.txtmsg.Visible = TruefMainForm.Map1.MousePointer = miHourglassCursor Screen.MousePointer = 11DoEvents' '' '' '' '' '' '' '' '' '' returns data page total Number DIM CN As New Adodb.ConnectionDIM RS As New Adodb.RecordSetdim n as integerim i as integeron error resume nextcn.cursorLocation = aduseclient
Cn.open constr
rs.cursorlocation = aduseclient
RS.Open SQL, CN, 1, 2IF NOT RS.EOF THEN DIM PAGEER '' '' 'Take the Total Total number DIM RCUNTS As long' '' When the total number of data is smaller than the set line, the maximum line of displaying data is obtained. DIM RSP as integer '' '' gets the location of the current record
rs.pagesize = rowsum rcounts = rs.recordcount if (rounts / rowsum) - 1> 0 THEN PAGESUM = ((Rcounts - 1) / ROWSUM) 1 Else PageSum = 1 End if if startp> rs.pagecount dam = rs.pagecount dam .Pagecount end if startp <1 THEN STARTP = 1 end if rs.absolutepage = startp grid1.clear with grid1
.Cols = rs.fields.count.Rows = ROWSUM 1.Row = 0 for i = 0 to rs.fields.count - 1 .col = i .text = rs.fields (i) .name next i statusbar1.panels .Item (2) .text = "A total of" "" str (rs.Recordcount) " " record ".cols = rs.fields.count.Rows = ROWSUM 1 for i = 1 To ROWSUM FOR J = 0 to COLSUM - 1.TextMatrix (i, j) = rs.fields (j) & "Next rs.movenext if xi = een 断 到 到 到 g g 到 到 到Grid1.formatstring = FormatStrend IF
Dspend: rs.close cn.close set = nothing set cn = Nothing if PageSum = 0 Then EveryrowDisplay = 0 & "/" & pagesum else everyrowdisplay = startp & "/" & pagesum