Private Sub Command1_Click()
Adodc1.RecordSource = "select STCD,sum(isnull(DRP,0)) as DRP From ST_PPTN_R where TM between cast ('" & DTPicker2.Value & "" & Text3.Text & ":00:00' as datetime ) and cast ( '" & DTPicker3.Value & "" & Text4.Text & ":00:00' as datetime) Group By STCD"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1.Recordset
DataGrid1.Refresh
说明:vb6.0中用DTPicker控件来显示日期,用Text控件显示的数值表示整时,分秒默认为:00:00。
select 语句是要查询DTPicker控件和Text控件显示的时间之间的数据。
sql数据库表中字段TM的数据类型是datatime,存储现实是(2011-5-19 18:00:00).
运行上面程序,出现错误是“从char数据类型到datetime数据类型的转换导致datetime值越界”
上面错误怎么改正?或还有其它代码能现实其功能?
Adodc1.RecordSource = "select STCD,sum(isnull(DRP,0)) as DRP From ST_PPTN_R where TM between cast ('" & DTPicker2.Value & "" & Text3.Text & ":00:00' as datetime ) and cast ( '" & DTPicker3.Value & "" & Text4.Text & ":00:00' as datetime) Group By STCD"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1.Recordset
DataGrid1.Refresh
说明:vb6.0中用DTPicker控件来显示日期,用Text控件显示的数值表示整时,分秒默认为:00:00。
select 语句是要查询DTPicker控件和Text控件显示的时间之间的数据。
sql数据库表中字段TM的数据类型是datatime,存储现实是(2011-5-19 18:00:00).
运行上面程序,出现错误是“从char数据类型到datetime数据类型的转换导致datetime值越界”
上面错误怎么改正?或还有其它代码能现实其功能?
Adodc1.RecordSource = "select STCD,sum(isnull(DRP,0)) as DRP From ST_PPTN_R where TM between '" & DTPicker2.Value & " " & Text3.Text & ":00:00' and '" & DTPicker3.Value & " " & Text4.Text & ":00:00' Group By STCD"
See AlsoConverts a character expression to a date expression.SyntaxCTOD(cExpression)ReturnsDateArgumentscExpressionSpecifies a character expression for which CTOD( ) returns a Date-type value.
这样试试