VB中怎样用ADO把多次查询的结果依次显示在Msflexgrid中 10
下面是我编写的查询代码:PrivateSubtext1_KeyPress(KeyAsciiAsInteger)DimrsAsNewADODB.RecordsetDimst...
下面是我编写的查询代码:
Private Sub text1_KeyPress(KeyAscii As Integer)
Dim rs As New ADODB.Recordset
Dim strsql As String
Dim num As Integer
Dim a As Double
Dim b As Integer
dmtm = Trim(Text1.Text)
nsjg = Trim(Text2.Text)
If KeyAscii = 13 Then
strsql = "select * from 商品管理 where 代码='" & Text1.Text & "'"
Set rs = getrs(strsql)
If rs.RecordCount > 0 Then
rs.MoveFirst
With MSFlexGrid1
For i = 1 To rs.RecordCount
Row = i
Col = 0
MSFlexGrid1.TextMatrix(i, 0) = rs.Fields("代码").Value
Col = 1
MSFlexGrid1.TextMatrix(i, 1) = rs.Fields("品名").Value
Col = 2
MSFlexGrid1.TextMatrix(i, 2) = rs.Fields("售价").Value
rs.MoveNext
Next i
End With
End If
End If
End Sub 展开
Private Sub text1_KeyPress(KeyAscii As Integer)
Dim rs As New ADODB.Recordset
Dim strsql As String
Dim num As Integer
Dim a As Double
Dim b As Integer
dmtm = Trim(Text1.Text)
nsjg = Trim(Text2.Text)
If KeyAscii = 13 Then
strsql = "select * from 商品管理 where 代码='" & Text1.Text & "'"
Set rs = getrs(strsql)
If rs.RecordCount > 0 Then
rs.MoveFirst
With MSFlexGrid1
For i = 1 To rs.RecordCount
Row = i
Col = 0
MSFlexGrid1.TextMatrix(i, 0) = rs.Fields("代码").Value
Col = 1
MSFlexGrid1.TextMatrix(i, 1) = rs.Fields("品名").Value
Col = 2
MSFlexGrid1.TextMatrix(i, 2) = rs.Fields("售价").Value
rs.MoveNext
Next i
End With
End If
End If
End Sub 展开
2个回答
展开全部
Private Sub text1_KeyPress(KeyAscii As Integer)
Dim rs As New ADODB.Recordset
Dim strsql As String
Dim num As Integer
Dim a As Double
Dim b As Integer
dmtm = Trim(Text1.Text)
nsjg = Trim(Text2.Text)
If KeyAscii = 13 Then
strsql = "select * from 商品管理 where 代码='" & Text1.Text & "'"
Set rs = getrs(strsql)
If rs.RecordCount > 0 Then
rs.MoveFirst
With MSFlexGrid1
For i = MSFlexGrid1.rows To rs.RecordCount +MSFlexGrid1.rows 在这里修改一下就OK了
'Row = i 这些可以不用,因为TextMatrix(i, 0)已经指定了位置
'Col = 0
MSFlexGrid1.TextMatrix(i, 0) = rs.Fields("代码").Value
'Col = 1
MSFlexGrid1.TextMatrix(i, 1) = rs.Fields("品名").Value
'Col = 2
MSFlexGrid1.TextMatrix(i, 2) = rs.Fields("售价").Value
rs.MoveNext
Next i
End With
End If
End If
End Sub
Dim rs As New ADODB.Recordset
Dim strsql As String
Dim num As Integer
Dim a As Double
Dim b As Integer
dmtm = Trim(Text1.Text)
nsjg = Trim(Text2.Text)
If KeyAscii = 13 Then
strsql = "select * from 商品管理 where 代码='" & Text1.Text & "'"
Set rs = getrs(strsql)
If rs.RecordCount > 0 Then
rs.MoveFirst
With MSFlexGrid1
For i = MSFlexGrid1.rows To rs.RecordCount +MSFlexGrid1.rows 在这里修改一下就OK了
'Row = i 这些可以不用,因为TextMatrix(i, 0)已经指定了位置
'Col = 0
MSFlexGrid1.TextMatrix(i, 0) = rs.Fields("代码").Value
'Col = 1
MSFlexGrid1.TextMatrix(i, 1) = rs.Fields("品名").Value
'Col = 2
MSFlexGrid1.TextMatrix(i, 2) = rs.Fields("售价").Value
rs.MoveNext
Next i
End With
End If
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
For i = 0 To rs.recordcount - 1
MSFlexGrid1.Rows = rs.recordcount + 1
For j = 0 To MSFlexGrid1.Cols - 1
If IsNull(rs(j).Value) Then '判断记录集字段值是否为空
Else
MSFlexGrid1.TextMatrix(i + 1, j) = rs(j).Value
End If
Next j
rs.MoveNext
Next i
conn.Close
MSFlexGrid1.Rows = rs.recordcount + 1
For j = 0 To MSFlexGrid1.Cols - 1
If IsNull(rs(j).Value) Then '判断记录集字段值是否为空
Else
MSFlexGrid1.TextMatrix(i + 1, j) = rs(j).Value
End If
Next j
rs.MoveNext
Next i
conn.Close
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询