VB+ADO+DataGrid+Access数据查询问题~~(急)
IfCombo1.Text<>""AndCombo2.Text<>""ThenDataGrid1.ColumnHeaders=TrueDataGrid1.Caption=...
If Combo1.Text <> "" And Combo2.Text <> "" Then
DataGrid1.ColumnHeaders = True
DataGrid1.Caption = "所有" & Combo1.Text & "→" & Combo2.Text & "之间列车数据信息记录"
Label1.Caption = Adodc1.Recordset.RecordCount & "条列车信息" '统计信息总记录数
strsql = "Select tx_trains.trainID as 车次,tx_trains.type as 类型,tx_trains.beginStation as 始发站,tx_trains.endStation as 终点站, _tx_trains.beginTime as 发时,tx_trains.endTime as 到时,tx_trains.times as 历时,tx_trains.mileage as 里程,tx_trains.stationnum as 过站 _from tx_trains where tx_trains.beginStation='" & Combo1.Text & "' And tx_trains.endStation='" & Combo2.Text & "'"
Adodc1.RecordSource = strsql
-----------------------------------------------------------
我在窗体上加了两个Combo,其中Combo1.Text是“始发站”站名,Combo2.Text是“终点站”站名,为什么安装上面的SQL语句查询,总是返回数据表的所有信息啊?而不是根据条件查询的结果...急寻高手帮忙!!!还有,我不想用ADO控件,可是用ADO编写代码又做不好,能否顺便指点下?通过后另加高分!先歇歇啦。
加了Adodc1.Refresh还是不行啊... 展开
DataGrid1.ColumnHeaders = True
DataGrid1.Caption = "所有" & Combo1.Text & "→" & Combo2.Text & "之间列车数据信息记录"
Label1.Caption = Adodc1.Recordset.RecordCount & "条列车信息" '统计信息总记录数
strsql = "Select tx_trains.trainID as 车次,tx_trains.type as 类型,tx_trains.beginStation as 始发站,tx_trains.endStation as 终点站, _tx_trains.beginTime as 发时,tx_trains.endTime as 到时,tx_trains.times as 历时,tx_trains.mileage as 里程,tx_trains.stationnum as 过站 _from tx_trains where tx_trains.beginStation='" & Combo1.Text & "' And tx_trains.endStation='" & Combo2.Text & "'"
Adodc1.RecordSource = strsql
-----------------------------------------------------------
我在窗体上加了两个Combo,其中Combo1.Text是“始发站”站名,Combo2.Text是“终点站”站名,为什么安装上面的SQL语句查询,总是返回数据表的所有信息啊?而不是根据条件查询的结果...急寻高手帮忙!!!还有,我不想用ADO控件,可是用ADO编写代码又做不好,能否顺便指点下?通过后另加高分!先歇歇啦。
加了Adodc1.Refresh还是不行啊... 展开
4个回答
展开全部
正确的语句如下:
If Combo1.Text <> "" And Combo2.Text <> "" Then
DataGrid1.ColumnHeaders = True
DataGrid1.Caption = "所有" & Combo1.Text & "→" & Combo2.Text & "之间列车数据信息记录"
Label1.Caption = Adodc1.Recordset.RecordCount & "条列车信息" '统计信息总记录数
strsql = "Select tx_trains.trainID as 车次,tx_trains.type as 类型,tx_trains.beginStation as 始发站,tx_trains.endStation as 终点站, tx_trains.beginTime as 发时,tx_trains.endTime as 到时,tx_trains.times as 历时,tx_trains.mileage as 里程,tx_trains.stationnum as 过站 from tx_trains where tx_trains.beginStation='" & Combo1.Text & "' And tx_trains.endStation='" & Combo2.Text & "'"
Adodc1.RecordSource = strsql
Adodc1.Refresh
End If
有几处语法错误:
_tx_trains.beginTime 不应该有前面的下划线。
_from 不应该有前面的下划线。
recordsource赋值后,应该用Refresh进行刷新。
If Combo1.Text <> "" And Combo2.Text <> "" Then
DataGrid1.ColumnHeaders = True
DataGrid1.Caption = "所有" & Combo1.Text & "→" & Combo2.Text & "之间列车数据信息记录"
Label1.Caption = Adodc1.Recordset.RecordCount & "条列车信息" '统计信息总记录数
strsql = "Select tx_trains.trainID as 车次,tx_trains.type as 类型,tx_trains.beginStation as 始发站,tx_trains.endStation as 终点站, tx_trains.beginTime as 发时,tx_trains.endTime as 到时,tx_trains.times as 历时,tx_trains.mileage as 里程,tx_trains.stationnum as 过站 from tx_trains where tx_trains.beginStation='" & Combo1.Text & "' And tx_trains.endStation='" & Combo2.Text & "'"
Adodc1.RecordSource = strsql
Adodc1.Refresh
End If
有几处语法错误:
_tx_trains.beginTime 不应该有前面的下划线。
_from 不应该有前面的下划线。
recordsource赋值后,应该用Refresh进行刷新。
展开全部
我也看不出哪里出错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是不是要加adodc1.fresh
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先看下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询