我正在研究一個Sindows Forms應用程序,以幫助保持一些掃描儀的庫存。我正在使用Linq2Sql,每個表都有一個id
列。在我的維修歷史表格上。我正在嘗試使用庫存表中的序列號,以便它進入數據庫並從表中查找sID並返回正確的值,但是當我將所有輸入的數據發送到歷史表時,它會得到一個空引用異常。vb.net form linq nullreferenceexception
Dim db As New DataClasses1DataContext
Dim rep As Scanner_Repair_History
Dim scan = (From Scanner_Inventory In db.Scanner_Inventories Where scannerid.Text = Scanner_Inventory.SN Select Scanner_Inventory.SID).FirstOrDefault
rep.SID = scan
rep.Date_Broken = datebroke.Value
rep.Description = description.Text
rep.Send_Date = senddate.Text
rep.Recieve_Date = recievedate.Text
rep.Cost = cost.Text
rep.PlantID = plantid.Text
rep.BID = brokenid.Text
rep.RMAnumber = rmanum.Text
db.Scanner_Repair_Histories.InsertOnSubmit(rep)
db.SubmitChanges()
的【什麼是一個NullReferenceException,如何解決呢?(可能的複製http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do- i-fix-it) – Bugs