2012-08-12 146 views
0

我加載一個DataTable到DataGrid視圖通過調用下面的函數:VB.NET數據表列類型

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

這是一個類型數據集? – 2012-08-12 15:53:18

+0

t1是一個Datatable – user1590636 2012-08-12 15:55:26

回答

2

檢查要在其中傳遞日期值列的類型確保該值不int。如果它是的話將其更改爲datetime

編輯 轉到的屬性你的數據表,並將列類型更改爲datetime