1

我正在使用在旧的 C# 帖子中找到的一些代码来使用 VB.net 将 DAO 插入到 Access 中。我运行代码来插入数字,它运行良好。但是,当我尝试date在哈希之间插入一个字符串时,我得到一个Data type conversion error. 我看了一下,但看不到如何更改记录集字段的数据类型以接受字符串/日期。

这是代码:

    Dim dbEngine As New dao.DBEngine
    Dim db As dao.Database = dbEngine.OpenDatabase(DataDirectoryName & DatabaseName)
    Dim rs As dao.Recordset = db.OpenRecordset(TableName)

    Dim myFields As dao.Field() = New dao.Field(FieldNames.Count - 1) {}
    For k As Integer = 0 To FieldNames.Count - 1
        myFields(k) = rs.Fields(FieldNames(k))
    Next

    dbEngine.BeginTrans()
    For i As Double = 0 To Data.Rows - 1
        rs.AddNew()
        For k As Integer = 0 To FieldNames.Count - 1
            rs.Fields(k).Value = Data.Value(k, i)
            rs.Fields(FieldNames(k)).Value = Data.Value(k, i)
            myFields(k).Value = Data.Value(k, i)
        Next
        rs.Update()
    Next
    dbEngine.CommitTrans()
    rs.Close()
    db.Close()

这是一行数据:

(0) = "74"
(1) = "#01 February 2012 00:02:00#"
(2) = "40"
(3) = "130"
(4) = "60"

'Data' 是一个自定义类,它是一个list (of list (of string)).

4

1 回答 1

1

虽然 VBA 将接受您的字符串上的日期分隔符,例如 #11 February 2013 20:23:11# 似乎 VB.Net 不会,但是它确实接受 MS Access 更新。

 rs.Fields("adate").Value = CDate("11 February 2013 20:23:11")
于 2013-02-14T14:47:02.920 回答