读书人

VB6 datagrid的两个有关问题()

发布时间: 2013-11-09 17:06:41 作者: rapoo

VB6 datagrid的两个问题(求助)
问题一:
datagrid表头的序号在筛选后就乱了,怎么重新生成呢?
NO Tester ID Cell ID Group Mode Yield
1 6084 01 S11 J1B 25%
2 6083 02 S12 J1B 5%
3 6082 03 S13 J1B 45%
4 6081 04 S21 J1B 21%
5 6080 05 S12 J1B 33%
筛选后就变成了
NO Tester ID Cell ID Group Mode Yield
1 6084 01 S11 J1B 25%
2 6083 02 S12 J1B 5%
3 6082 03 S13 J1B 45%
5 6080 05 S12 J1B 33%
我想让它自动编号为:
NO Tester ID Cell ID Group Mode Yield
1 6084 01 S11 J1B 25%
2 6083 02 S12 J1B 5%
3 6082 03 S13 J1B 45%
4 6080 05 S12 J1B 33%
该如何实现?
问题二:
统计出Group列下S1的记录个数显示到Label1中,请各位高手帮忙解答.

引用
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\mdb.mdb;Persist Security Info=False"
Adodc2.CommandType = adCmdText
Adodc2.RecordSource = "select * from AllZone where [group] like 'S1%'"
Set DataGrid2.DataSource = Adodc2
datagrid2.columns(5).numberformat="#0%"

[解决办法]
如果你要用上面的方式逐个记录改写编号,那当然就知道记录数了。

否则:
ADODC2.Recordset.MoveLast
ADODC2.Recordset.MoveFirst
Label1.Caption = ADODC2.Recordset.RecordCount

[解决办法]
select 序号= IDENTITY(INT,1,1),
a.Tester ID,
a.Cell ID,
a.Group,
a.Mode,
a.Yield
into #temp
from AllZone where [group] like 'S1%'
go
select * from #temp
go
drop table #temp
go

楼上的code我加了个文字特效,显示不对,用这个。
[解决办法]
如果你的sql是2005以上,上面的查询语句还可进一步简化成:
select RANK() OVER (ORDER BY Cell ID ) AS 序号,
Tester ID,
Cell ID,
Group,
Mode,
Yield
from AllZone where [group] like 'S1%'

另外字段名称别在中间加空格,比如你的Cell ID字段,写成Cell_ID较妥当。
------解决方案--------------------


另外做一个查询:

Select Left([Group], 2) As Sub_Group, Count([NO]) As Num_Rec From AllZone Group By Left([Group], 2) Order By Left([Group], 2)

这样可以得到一个记录集:
S1, xx
S2, yy
...

实际上方法很多,看怎样适合你的操作过程。

读书人网 >VB

热点推荐