vb中sql查询语句

sql语句是这样写的

sqltxt = "select h_date as 发生时间,sum(l_time) as 持续总时间,sum(area_disa) as 受灾总面积 from datainfo where h_date like '%" & st.Text & "%' group by h_date"

但是下面这段代码

rs.Open sqltxt, conn, adOpenKeyset, adLockReadOnly
MsgBox rs.RecordCount
If rs.RecordCount = 0 Then Exit Function
With MSChart1
'设置图形显示的类型
.RowCount = rs.RecordCount '设置显示的图形数
.ColumnCount = rs.RecordCount '设置标签数
.FootnoteText = "气象查询系统统计图表"
.TitleText = mscinfo & "统计图"
.ShowLegend = True
For K = 1 To .Plot.SeriesCollection.Count
.Plot.SeriesCollection(K).DataPoints(-1).DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
Next

For j = 1 To rs.RecordCount
If rs.EOF Then Exit Function
.Row = j
.RowLabel = rs(j - 1).Value

For i = 1 To rs.RecordCount
.Column = i
.ColumnLabel = "党" & i '
.Data = rs(i).Value '填充当前活动列的值
rs.MoveNext
Next
'rs.MoveNext
Next
End With

提示

.Data = rs(i).Value '填充当前活动列的值

这一行错误,原因是 无效使用null 但是调试的时候,data是有值的

意思就是调试的时候,data可以看到是有具体的数字的,但是后面的rs这个值就是null

不知道是为什么,请大侠帮帮忙

弄好了追加50分

1. For j = 1 To rs.RecordCount 改成 For j = 0 To rs.RecordCount - 1
2. .Data = rs(i).Value 改成 rs.Fields(i).Value
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-07-16
.Data = rs(i).Value改成
if isnull(rs.fields(i).value)= false then .Data = rs(i).Value
对变量赋"Null"值会出错,先要去除"Null"项的值
第2个回答  2009-07-07
For i = 1 To rs.RecordCount 改成 For i = 0 To 2

参考资料:尝试

相似回答
大家正在搜