0

我通过调用以下函数将数据表加载到数据网格视图:

 Public Sub GetData(ByVal selectCommand As String, ByVal bindingSource As BindingSource, ByVal table As DataTable)
    Try
        Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\adm\Desktop\222.mdb"
        Me.dataAdapter = New OleDbDataAdapter(selectCommand, connectionString)
        Dim commandBuilder As New OleDbCommandBuilder(Me.dataAdapter)
        table.Locale = System.Globalization.CultureInfo.InvariantCulture
        Me.dataAdapter.Fill(table)
        bindingSource.DataSource = table
    Catch ex As OleDbException
        MessageBox.Show(ex.Message)
    End Try
End Sub

这是函数调用:

GetData("select * from products where ID=1 or ID=2", bindingSource1, t1)

现在,数据表是否定义了来自源数据库的列类型?因为当我尝试将数据添加到 DateTime 列时,它说该列是整数类型,但在 Access 中我可以看到它是一个 DateTime 列。那么我需要为每列指定每种类型还是自动完成?

4

1 回答 1

2

检查您传递日期值的列的类型,确保该值不是int。如果是,则将其更改为datetime

编辑 转到数据表的属性并将列类型更改为datetime

于 2012-08-12T15:56:47.590 回答