vb中加载窗体后怎样直接显示数据库中的数据
窗体中有一个表格控件,我想在窗体加载时让表格中显示连接数据库中的信息,可是在编译的时候,编译通过,没有报错,但是就是不显示数据,这是怎么回事啊!代码如下,求高手指点!Pu...
窗体中有一个表格控件,我想在窗体加载时让表格中显示连接数据库中的信息,可是在编译的时候,编译通过,没有报错,但是就是不显示数据,这是怎么回事啊!代码如下,求高手指点!
Public txtSQL As String
Private Sub Form_Load()
ShowTitle '显示表头
ShowData '显示数据
flagMedit = True
End Sub
Private Sub ShowTitle()
Dim i As Integer
With msgList
.TextMatrix(1, 0) = "药品编码"
.TextMatrix(1, 1) = "药品名称"
.TextMatrix(1, 2) = "药品类别"
.TextMatrix(1, 3) = "规格"
.TextMatrix(1, 4) = "单位"
.TextMatrix(1, 5) = "生产日期"
.TextMatrix(1, 6) = "生产批号"
.TextMatrix(1, 7) = "售价"
.TextMatrix(1, 8) = "厂价"
.TextMatrix(1, 9) = "库存量"
.TextMatrix(1, 10) = "有效期"
.TextMatrix(1, 11) = "入库日期"
For i = 0 To 11
.ColAlignment(i) = 0
Next
.FixedRows = 1 '固定表头
.FillStyle = flexFillRepeat '表头项居中
.Col = 0
.Row = 0
.RowSel = 1
.ColSel = .Cols - 1
.CellAlignment = 4
End With
End Sub
Private Sub ShowData() '调用ShowData函数,显示记录列表
Dim i As Integer
Dim mrc As ADODB.Recordset
Dim MsgText As String
txtSQL = "select * from InStores "
Set mrc = ExecuteSQL(txtSQL, MsgText)
With msgList
.Rows = 1
Do While Not mrc.EOF '将数据库中的记录显示在表格中
.Rows = .Rows + 1 '显示下一行数据
For i = 1 To mrc.Fields.Count
Select Case mrc.Fields(i - 1).Type '根据数据类型显示
Case ad
.TextMatrix(.Rows - 1, i) = mrc.Fields(i - 1) & ""
End Select
Next i
mrc.MoveNext
Loop
End With
mrc.Close
End Sub 展开
Public txtSQL As String
Private Sub Form_Load()
ShowTitle '显示表头
ShowData '显示数据
flagMedit = True
End Sub
Private Sub ShowTitle()
Dim i As Integer
With msgList
.TextMatrix(1, 0) = "药品编码"
.TextMatrix(1, 1) = "药品名称"
.TextMatrix(1, 2) = "药品类别"
.TextMatrix(1, 3) = "规格"
.TextMatrix(1, 4) = "单位"
.TextMatrix(1, 5) = "生产日期"
.TextMatrix(1, 6) = "生产批号"
.TextMatrix(1, 7) = "售价"
.TextMatrix(1, 8) = "厂价"
.TextMatrix(1, 9) = "库存量"
.TextMatrix(1, 10) = "有效期"
.TextMatrix(1, 11) = "入库日期"
For i = 0 To 11
.ColAlignment(i) = 0
Next
.FixedRows = 1 '固定表头
.FillStyle = flexFillRepeat '表头项居中
.Col = 0
.Row = 0
.RowSel = 1
.ColSel = .Cols - 1
.CellAlignment = 4
End With
End Sub
Private Sub ShowData() '调用ShowData函数,显示记录列表
Dim i As Integer
Dim mrc As ADODB.Recordset
Dim MsgText As String
txtSQL = "select * from InStores "
Set mrc = ExecuteSQL(txtSQL, MsgText)
With msgList
.Rows = 1
Do While Not mrc.EOF '将数据库中的记录显示在表格中
.Rows = .Rows + 1 '显示下一行数据
For i = 1 To mrc.Fields.Count
Select Case mrc.Fields(i - 1).Type '根据数据类型显示
Case ad
.TextMatrix(.Rows - 1, i) = mrc.Fields(i - 1) & ""
End Select
Next i
mrc.MoveNext
Loop
End With
mrc.Close
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询