需要帮助来保存日期以便在vb6中访问 [英] need help to save date to access in vb6

查看:108
本文介绍了需要帮助来保存日期以便在vb6中访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,在我的vb6项目中,我有一个按钮,可以从文本框向ms访问数据库添加新行

,其中一个字段是日期数据类型。我尝试了这段代码,但它不起作用

Hi all , in my vb6 project i have a button that adds new row to ms access database from textboxes
, One of the fields is with date data type . i tried this code but it does not work

Adodc1.Recordset.AddNew
Adodc1.Recordset(0).Value = val(text1.text)
Adodc1.Recordset(1).Value = text2.text
Adodc1.Recordset(2).Value = val(text3.text)
Adodc1.Recordset(3).Value = "# " & Text4.Text & "#"       ' this to send date to specified cell in a field

Adodc1.Refresh
DataGrid1.Refresh





如果有任何机构有这个解决方案,请帮助我:)并感谢



if any body have this solution , so help me :) and thanks

推荐答案

我假设您知道如何添加参考 MS ActiveX数据库对象xx库 [ ^



要将数据添加到MS Access数据库,您需要创建ADODB.Connection [ ^ ]。接下来,您需要创建 ADODB.Command [ ^ ]使用此sql语句:

I assume that you know how to add reference to MS ActiveX Database Objects x.x libary[^].

To add data to MS Access database, you need to create ADODB.Connection[^]. Next, you need to create ADODB.Command[^] with this sql statement:
INSERT INTO <TableName> (NumericField, TextField, DateField)
VALUES (1, 'SomeText', #yyyy/MM/dd#)



最后,你需要打电话给执行方法 [< a href =http://msdn.microsoft.com/en-us/library/windows/desktop/ms681559%28v=vs.85%29.aspxtarget =_ blanktitle =New Window> ^ ]。



注意:连接字符串 [< a href =http://www.connectionstrings.com/access/target =_ blanktitle =新窗口> ^ ]取决于MS Access数据库版本( *。 mdb * .accdb )。


Finally, you need to call Execute Method[^].

Note: Connection string[^] depends of MS Access database version (*.mdb or *.accdb).


我发现了我的错误,发送日期是错误的vb6到数据库有两个#[在开始和结束]如果使用adodc1.recordset.addnew方法....但我们应该添加#开始和结束t他约会如果我们使用sql查询的方法..感谢大家的评论和答案:)
i found my error , it was wrong to send date from vb6 to database with two # [in begin and end] in case if used adodc1.recordset.addnew Method .... But we should add # to begin and end of the date if we used the method of sql query .. thanks for you all for you comments and Answers :)


这篇关于需要帮助来保存日期以便在vb6中访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆