Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 315729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:19:06+00:00 2026-05-12T08:19:06+00:00

I am using ADO.NET Entity framework for connect db and get data. I want

  • 0

I am using ADO.NET Entity framework for connect db and get data. I want if there is no data in object it will write “EMPTY FIELD” if it’s full than it will write to listview coloumn data from the db. I am getting ‘System.NullReferenceException’ error when there is a null object in objectcontext.Dont return a ” EMPTY ROW” string.

Here is my code:

   using (ITSEntities arama = new ITSEntities())
            {
                var sql = "SELECT VALUE s_tesis FROM ITSEntities.TB_SAGLIK_TESIS AS s_tesis WHERE s_tesis.TESIS_AD like @p1";
                ObjectQuery<TB_SAGLIK_TESIS> sorgu = new ObjectQuery<TB_SAGLIK_TESIS>(sql, arama).Include("TB_IL").Include("TB_TESIS_TIPI").Include("TB_TESIS_TURU");
                sorgu.Parameters.Add(new ObjectParameter("p1", String.Format("{0}%", btnAra.Text)));

                                   listTesis.Items.Clear();

                foreach (var item in sorgu)
                {

                    ListViewItem listitem = new ListViewItem { Text = item.KODU.ToString() };
                    listitem.SubItems.Add(item.TESIS_AD);
                    listitem.SubItems.Add(String.IsNullOrEmpty(item.TB_IL.ADI) ? "EMPTY ROW" : item.TB_IL.ADI);
                    listitem.SubItems.Add(String.IsNullOrEmpty(item.TB_TESIS_TIPI.TIP_AD) ? "EMPTY ROW" : item.TB_TESIS_TIPI.TIP_AD);
                    listitem.SubItems.Add(String.IsNullOrEmpty(item.TB_TESIS_TURU.TESIS_TURU) ? "EMPTY ROW" :item.TB_TESIS_TURU.TESIS_TURU);
                    listTesis.Items.Add(listitem);
                }
            }
        }
        catch (Exception ex)
        {

            MessageBox.Show(ex.InnerException.ToString());
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:19:06+00:00Added an answer on May 12, 2026 at 8:19 am

    I don’t know EF, but you’re dereferencing 2 objects in the following lines:

    ListViewItem listitem = new ListViewItem { Text = item.KODU.ToString() };
    listitem.SubItems.Add(String.IsNullOrEmpty(item.TB_IL.ADI) ? "EMPTY ROW" : item.TB_IL.ADI);
    listitem.SubItems.Add(String.IsNullOrEmpty(item.TB_TESIS_TIPI.TIP_AD) ? "EMPTY ROW" : item.TB_TESIS_TIPI.TIP_AD);
    listitem.SubItems.Add(String.IsNullOrEmpty(item.TB_TESIS_TURU.TESIS_TURU
    

    If the container object (KODU, TB_IL, TB_TESIS_TIPI. or TB_TESIS_TURU) is ever null, then you’d get a NullReferenceException.

    My guess is that these are table names, and that some rows don’t have a corresponding JOIN to those tables. In any case, you’d probably need to rewrite those as:

    ListViewItem listitem = new ListViewItem { Text = (item.KODU ?? "").ToString() };
    listitem.SubItems.Add(
        (item.TB_TL == null || String.IsNullOrEmpty(item.TB_IL.ADI)) 
        ? "EMPTY ROW" : item.TB_IL.ADI
    );
    

    To make it a bit cleaner, a method:

    string EmptyRowIfNull<T>(T o, Func<T, string> p) {
       string s;
       if (o != null) {
           s = p(o);
       }
       return string.IsNullOrEmpty(s) ? "EMPTY ROW" : s;
    }
    
    listitem.SubItems.Add(EmptyRowIfNull(item.TB_IL, t => t.ADI));
    listitem.SubItems.Add(EmptyRowIfNull(item.TB_TESIS_TIPI, t => t.TIP_AD));
    listitem.SubItems.Add(EmptyRowIfNull(item.TB_TESIS_TURU, t => t.TESIS_TURU));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 534k
  • Answers 534k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Seems like db_clean() is a customized helper which is calling… May 17, 2026 at 12:46 am
  • Editorial Team
    Editorial Team added an answer If you kill the connection on which the update was… May 17, 2026 at 12:46 am
  • Editorial Team
    Editorial Team added an answer You can't. ActiveX is an IE-only thing. If you need… May 17, 2026 at 12:46 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Using Ado.Net Entity framework, I am trying to get the 'top 3' items in
[ I am new to ADO.NET and the Entity Framework, so forgive me if
I'm developing an ASP.NET app (C#) that connect to SQL Server 2008 using ADO.NET
I've installed the System.Data.SQLite ADO.NET Provider from http://sqlite.phxsoftware.com/ . I can connect to the
I have a simple ADO.NET Entity Framework 4.0 model (edmx) which defines database tables
I want to update my ADO.NET Entities Framework Model from the database, but I
I'm trying to get server-side validation of an Entity Framework String Property to work.
I try to use SQL Server Compact Edition with Entity Framework in Visual Studio
Is it possible to manually connect to the database using sqlclient and sqlconnection (ie
I'd like ask a question about building applications in .NET that use data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.