我在执行如下命令行后:
cmd.commandtext="insert into s (username,rq) values ('" & text1.text & "',#" & text2.text & "#)"
cmd.execute如果text2.text="2003-11-14",在上述操作完成后,我退出程序,进入数据库查看,rq(日期型)的结果却变成了“1899-12-8”
如果rq是文本型,执行以下命令行就没有问题
cmd.commandtext="insert into s (username,rq) values ('" & text1.text & "','" & text2.text & "')"
cmd.execute
这是什么原因呢?

解决方案 »

  1.   

    你用的數據庫是什么?text2 的文本輸入規范嗎?
      

  2.   

    access中对时间的操作要用#   #
    所以在拼字符串的时候要加上 '   '来把要操作的字段引起来
      

  3.   

    ('" & text1.text & "','" & text2.text & "')
    很明显,变量有误,正确的话,text.text的第一个t应自动转换为大写“T”
    不知道你打开对象的方法,试着去掉单引号吧,再不行改为#,或者用format先格式化它,,
      

  4.   

    改为试试看 
    cmd.commandtext="insert into s (username,rq) values ('" & text1.text & "',#'" & text2.text & "'#)"
    cmd.execute
      

  5.   

    1、这是ACCESS写法
    cmd.commandtext="insert into s (username,rq) values ('" & text1.text & "',#'" & text2.text & "'#)"
    2、SQL写法
    cmd.commandtext="insert into s (username,rq) values ('" & text1.text & "','" & text2.text & "')"