首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

已知日期"2006-10"小弟我想往表里添加记录"2006-10-1"至"2006-10-31"请教

2012-01-19 
已知日期2006-10,我想往表里添加记录2006-10-1至2006-10-31,请问怎么解决.我是准备在VB下来调用实现

已知日期"2006-10",我想往表里添加记录"2006-10-1"至"2006-10-31",请问怎么解决.
我是准备在VB下来调用实现这条语句的.
SELECT   datediff( 'd ',#2007-1#,dateadd( 'm ',1,#2007-1#))这个可以算出当月有多少天,我想用循环来做,但是总是出错.大家给我点意见或方法,谢谢了.

Dim   yp1   As   String
        Dim   re   As   Integer
        Adodc2.RecordSource   =   ( "SELECT   datediff( 'd ',#2007-10#,dateadd( 'm ',1,#2007-10#)) ")
        Adodc2.Refresh
        re   =   Adodc2.Recordset.Fields(0)
       
        For   i   =   1   To   re
                yp1   =   "insert   into   aaa(WorkDate)   values(# "   &   DateSerial(2007,   10,   i)   &   "#) "
                Adodc2.RecordSource   =   (yp1)
                Adodc2.Refresh
        Next
日期我显示出来了,但是,我这么写,系统提示 "对象关闭时,不允许操作 "
请问是怎么回事啊?谢谢..



[解决办法]
建议直接使用 ADODB.Connection

应该不使用 # ,而是 '



[解决办法]
也可以在VB下求得:
Function getMonthDays(theDate As Date) As Integer
Dim dDate As Date

dDate = DateSerial(Year(theDate), Month(theDate), 1)

getMonthDays = DateDiff( "d ", dDate, DateAdd( "m ", 1, dDate))
End Function

热点排行