我通过调用以下函数将Datatable加载到datagrid视图:
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列。那么我需要为每列指定每种类型,还是自动完成?
答案 0 :(得分:2)
检查传递日期值的列的类型。确保该值不是int
。如果是,请将其更改为datetime
< / p>
修改强>
转到数据表的属性,将列类型更改为datetime