需要来自Access的.net的OleDbType数据

时间:2014-05-09 19:52:16

标签: database vb.net ms-access types oledb

我正在尝试从Access数据库中获取OleDb数据类型。我的项目的最终目标是构建一个程序,为任何访问数据库动态构建适当的接口。

我现在的核心问题是,当我拉出它时,我无法从表中获取正确的数据类型(每列中的数据类型)。我可能做错了什么或遗漏了什么,但我似乎无法找到解决这个问题的方法。

这是我的代码到目前为止(其中一些已被注释掉)

' structure for fields
Private Structure field
    Public name As String
    Public max As Integer
    Public datatype As System.Data.OleDb.OleDbType
    'Public mapping As System.Data.MappingType
    'Public extra As System.Data.PropertyCollection
    'Public expression As String
End Structure

Public Function getFieldsWithData(ByVal tbl As String) As ArrayList

    ' empty array for new fields
    _fields.Clear()

    ' build a table object for use
    Dim dt As New DataTable

    ' get the table data
    dt = getTable(tbl)

    For n As Integer = 0 To (dt.Columns().Count - 1)
        ' do not add the id field - string.compare returns 0 if they are equal
        If (String.Compare(dt.Columns(n).ToString, "id", True) <> 0) Then
            ' add the fields structure - name and data type
            Dim newFld As New field
            newFld.name = dt.Columns(n).ColumnName
            newFld.max = dt.Columns(n).MaxLength
            newFld.datatype = dt.Columns(n).DataType

            'newFld.mapping = dt.Columns(n).ColumnMapping
            'newFld.extra = dt.Columns(n).ExtendedProperties
            'newFld.expression = dt.Columns(n).Expression
            _fields.Add(newFld)
        End If
    Next

    ' cut off the excess slots from the arraylists
    _fields.TrimToSize()

    Return _fields

End Function

问题是`dt.Columns(n).DataType'从System.Type命名空间返回数据类型,而不是从OleDb命名空间(具体是System.Data.OleDb.OleDbType)返回。我一直在搜索MSDN,并像疯子一样搜索,试图找到一些东西,但我找不到东西。我不知道该怎样做才能继续前进。

其他一些可能有用的事情:
我正在使用VB.net来完成所有这些,
每个数据库对象都来自OleDb,
数据库是Access 2010,
我没有ADO经验(没有)。
我可以在基本级别阅读C#(如果你需要使用C#进行编码以向我展示一个好的答案) 我想要OleDbType,这样我就可以动态地将记录添加到已经存在的表中,并确保数据已准备好上传。 (即system.decimal!= oledbtype.currency)

0 个答案:

没有答案