我通过调用以下函数将数据表加载到数据网格视图:
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 列。那么我需要为每列指定每种类型还是自动完成?