hi ,
i am using ADO.NET Entity framework for connect db and get data.I wanna do if there is no data in object it will write "EMPTY FIELD" if its 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 codes ;
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());
}