我正在研究一个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