根据需要的SQL语句,装入数据到表格

'************************************   LMS 2017.10   ************************************
'*      装入VSFGrid(根据sql语句,从表 xt_grid中找对应字段填充表格) 默认gridcol_fieldlx = 1,文本型;2,数值型;3,日期型;4,boolean型;0,uniqueidentifier型
'*      参数: gridcol_fieldname="",该字段在表或视图或rst中不存在,Col_Start,默认从第一一列开始填写(fixcol=1)
'************************************   LMS 2017.10   ************************************
Public Sub FillVSFGrid(VSFGrid As VSFlexGrid, SQL As String, Grid_Code As String, Optional Col_Start As Integer = 1)
    Dim Xh As Long, Row As Long, KK As Integer
    Dim rst As New ADODB.RecordSet, rst1 As New ADODB.RecordSet, Field_Name As String     '----表中字段名
'On Error GoTo err_cl
    With VSFGrid
       .Rows = .FixedRows
       Set rst = Nothing
       Set rst = DataEnv.DataConn.Execute(SQL)
       If rst.EOF = False And rst.BOF = False Then
          rst.MoveFirst: Xh = 1: Row = .FixedRows
          Do While Not rst.EOF
             .AddItem ""
             .TextMatrix(Row, 0) = Xh
             For KK = Col_Start To .Cols - 1     '----求列对应的表中的字段名(例如:第1列--编码、第2列--名称等)
                 Set rst1 = Nothing
                 Set rst1 = DataEnv.DataConn.Execute("select * from xt_grid where grid_code='" + Trim(Grid_Code) + "' and gridcol_int=" & KK)
                 If Not (rst1.EOF And rst1.BOF) Then
                    Field_Name = Trim(rst1("gridcol_fieldname"))
                    If Field_Name = "" Then                '----该字段在表或视图中不存在
                       .TextMatrix(Row, KK) = ""
                    Else
                       If IsNull(rst(Field_Name)) Then
                          .TextMatrix(Row, KK) = ""
                       Else
                          If rst1("gridcol_fieldlx") = 4 Then        '----逻辑型4
                             .TextMatrix(Row, KK) = rst(Field_Name)  '----  IIf(rst(Field_Name) = 1, True, False)               '----- IIf(rst(Field_Name), "√", "")
                          ElseIf rst1("gridcol_fieldlx") = 2 Then    '----数值型2
                             .TextMatrix(Row, KK) = IIf(rst(Field_Name) = 0, "", rst(Field_Name))
                          ElseIf rst1("gridcol_fieldlx") = 3 Then    '----日期型3
                             .TextMatrix(Row, KK) = IIf(Year(rst(Field_Name)) < 2000, "", rst(Field_Name))
                          Else                                       '----uniqueidentifier型0 + 文本型1 + 日期型3
                             .TextMatrix(Row, KK) = rst(Field_Name)
                          End If
                       End If
                    End If
                 End If
             Next KK
             Xh = Xh + 1:  Row = Row + 1
             rst.MoveNext
          Loop
       End If
    End With
    Set rst = Nothing:  Set rst1 = Nothing
    Exit Sub
    
err_cl:
    Set rst = Nothing:  Set rst1 = Nothing
    MsgBox Err.Description, vbOKOnly + vbCritical, "系统提示"
End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值