且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

空引用错误(对象引用未设置为对象的实例.)

更新时间:2021-10-04 10:06:50

为解决您的错误,请执行此操作...


1)在这里放置行的断点...

For your solution of your error please do this...


1) put a break point of your line at this...

DataRow findRow = data.Tables["People"].Rows.Find(personID);



并按F10键,然后浏览您的findRow对象是否包含某些东西...

然后在用户即时解决方案窗口中将您的代码行粘贴到该行中
检查一下...



and press F10 then browse your findRow object if it will contain some thing or not...

then user immediate solution window and paste your line of code inside that
check this...

findRow["LastName"].ToString()


它会给你什么.....

如果它将为null,那么您在创建数据行时的代码有错误,请在此处进行更正.....


what it will give you.....

if it will give null then your code at datarow creation have something wrong and correct it there.....


谢谢Tejas!
问题是

Thank you Tejas!
The issue was that

int personID = Convert.ToInt16(selectedRow.Cells[0].Value);



在第一列中寻找东西.要做的是查看ID所在的数字列.因此,如果id在第三列中,则选定的行单元格值将为3


全部修复



was looking for stuff in the first column. What it was meant to be doing is looking in the number column where the ID was. so if id was in the third column then the selected row cells value would be 3


All fixed now