2014-03-13 38 views
1

我正試圖將Access數據庫中的數據加載到WinForms中的數據表中 ,但是錯誤「對象引用未設置爲對象「出現在代碼dt.Load(cmd.ExecuteReader)的第6行。dt.load(cmd.ExecuteReader)對象引用未設置爲對象的實例

 Call connect() 
     con.Open() 
     cmd = New OleDbCommand("Select * from Items_List_Table where GRF_No=" & Lbl_Grf_No.Text - 1, con) 
     MsgBox(Lbl_Grf_No.Text) 
     Dim dt As DataTable 
     dt.Load(cmd.ExecuteReader) 'Object reference not set to an instance of an object. 
     Dim row_count As Integer 
     row_count = dt.Rows.Count() 
     con.Close() 

This is a picture of the database

這是訪問數據庫。 GRF_NO,Item_Unique_Code和Item_Shop_Code是數字類型。所有其他人都是文本。

+0

的Lbl_Grf_No.Text - 1分的結果是18 所以我正在尋找有GRF_No 18 –

+1

行你的數據表中未初始化 – 2014-03-13 02:10:08

回答

1

嘗試實例變量這樣

昏暗DT作爲新的DataTable()

+0

對不起,延遲迴復。這完全奏效 –

相關問題