VB6中遍历DataGrid中某一行,某一列,所有行,所有列,是怎么写代码?非记录集操作
查了VB6的MSDN ,其中对DataGrid的Column集合有详细描述,就是没有对单个元素的操作,就像Delphi那样Column(n),Row(n)的进行遍历,最多就是第一行的数据,现在由于SQL数据语句本身的原因,现在就只能遍历DataGrid来截取数据,程序段如下
该程序是个麻将机销售管理程序
Public Sub Sqlsub(ByVal TabShop As String, ByVal Tabse As Integer) '构建sql语句,并生成记录集
Dim i As Integer, j As Integer
'这个时候已经获得了具体活动的店面名称代码
strSqlfirst = "Select after_dm as 店名, ' " & strPp(0).name & " 'as 品牌名,Count(after_pp) as 数量,AVG(CAST(after_je AS int)) as 均价,Count(after " _
& " From " & TabShop _
& " Where after_xh IN " _
& " ( " _
& " Select after_xh " _
& " From " & TabShop _
& " Where after_pp = ' " & strPp(0).name & " ' and after_rq BETWEEN Convert(Datetime, ' " & strpt1 & " ') AND Convert(Datetime, ' " & strpt2 & " ') " _
& " ) " _
& " group by after_dm "
'第一个品牌的SQL查询语句,这里默认世纪金钻为第一个默认品牌,考虑第一品牌可能替换,故单独生成SQL语句
strSqlLast = strSqlfirst
For i = 1 To 15 '品牌循环填充SQL语句
'根据循环所得具体品牌名称代码填充sqladd语句
strSqladd = " union all " _
& "Select after_dm as 店名, ' " & strPp(i).name & " 'as 品牌名,Count(after_pp) as 数量,AVG(CAST(after_je AS int)) as 均价 " _
& " From " & TabShop _
& " Where after_xh IN " _
& " ( " _
& " Select after_xh " _
& " From " & TabShop _
& " Where after_pp = ' " & strPp(i).name & " ' and after_rq BETWEEN Convert(Datetime, ' " & strpt1 & " ') AND Convert(Datetime, ' " & strpt2 & " ') " _
& " ) " _
& " group by after_dm "
strSqlLast = strSqlLast + strSqladd
Next
'构建联合查询的sql语句完毕,能够查询单店所指定所有品牌的信息
If Modmain.CrtFilRst(Modmain.con, Modmain.Rst_CliBan, strSqlLast, adCmdText, adOpenStatic, adLockReadOnly, False) Then
Set Me.DataGrid1(Tabse).DataSource = Modmain.Rst_CliBan '更新当前活动页面
End If
'析构,以便下次重新初始化
strSqlLast = " ": strSqlfirst = " ": strSqladd = " "
If Modmain.Rst_CliBan.State = adStateOpen Then
Set Modmain.Rst_CliBan = Nothing
End If
'OK
这里从DATAGrid中取数据,而不是在记录集中取数据该如何做呢?请高手指点,谢谢!
End Sub
[解决办法]
datagrid是与数据库绑定的,操作数据库本身就行.
你说的能扁历的控件,如msflexgrid是可以的.datagrid不行,你操作它,就是操作后台数据库表.