The object reference is not set To the instance of the object in Linq To SQL.

Source: Internet
Author: User

The object reference is not set To the instance of the object in Linq To SQL.

We encapsulate public void Delete (T entity) {db in DAL. getTable <T> (). deleteOnSubmit (entity); db. submitChanges () ;}delete public void Delete (stuInfo StuInfo) {db. delete (stuInfo);} this statement is a previously inserted StuInfo stuinfo = new StuInfo {StuAge = 18, StuNo = "s25900", StuSex = "male", StuSeat = 10, stuName = "", ClassID = 1}; stuInServicecs. remoevStuInfo (stuinfo); when we delete stuinfo, we will encounter the following problem: we have not set the object reference to the instance of the object: although this statement It already exists in the database, but it is still in the Free State when processing the stuinfo object. Therefore, you need to query stuinfo = stuInServicecs. GetByStuNo ("s25900") from the database using the primary key of stuinfo and then delete stuinfo.
But I feel a little redundant. I hope there are better solutions.

  


Linq to xml does not set the object reference to the instance of the object

If the object you are using is null, you may find that there is null in the case of your error. Please debug it in detail.
Hook. Lamda ~~ Yes ~

When you connect to the database through LINQ, the object reference is not set to the instance of the object.

It doesn't matter if the value of wealth is zero. Here we will discuss how to help each other ~
OrderID = Session ["userName"]. ToString (),
Your code needs to pass the value above. When you run this page, the system does not pass the value of Session ["userName"], and the system considers that you have not referenced the object as an instance.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.