vb中sql查询语句

来源:百度知道 编辑:UC知道 时间:2024/06/10 04:58:20
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.RecordCoun

1. For j = 1 To rs.RecordCount 改成 For j = 0 To rs.RecordCount - 1
2. .Data = rs(i).Value 改成 rs.Fields(i).Value

.Data = rs(i).Value改成
if isnull(rs.fields(i).value)= false then .Data = rs(i).Value
对变量赋"Null"值会出错,先要去除"Null"项的值

For i = 1 To rs.RecordCount 改成 For i = 0 To 2