Umut çelik

Umut çelik

  • NA
  • 33
  • 10.2k

c# read last record from database error

Apr 14 2016 3:37 AM

I can not find fault.please help me
 
Additional information: Object reference not set to an instance of an object
 
----------------------------------------------- 
 
public static ENOTLAR Select(ENOTLAR item)
{
try
{
SqlCommand com = new SqlCommand("NOTLAR_SonKayit", Baglanti.Con);
com.CommandType = CommandType.StoredProcedure;
if (com.Connection.State != ConnectionState.Open)
{
com.Connection.Open();
}
com.Parameters.AddWithValue("ID", item.ID);
SqlDataReader rdr = com.ExecuteReader();
while (rdr.Read())
{
item = new ENOTLAR();
item.ID = Convert.ToInt32(rdr["ID"]);
item.KONU = rdr["KONU"].ToString();
item.TARIH = Convert.ToDateTime(rdr["TARIH"]);
item.YAZI = rdr["YAZI"].ToString();
}
rdr.Close();
}
catch
{
item = null;
}
return item;
}
-------------- ---------------
private void LastNot()
{
ENOTLAR not = new ENOTLAR();
BLLNOTLAR.Skayit(not);
toolStripLabel3.Text = not.YAZI.ToString();
}
-------------------------- 
sql procedure
 
NOTLAR_SonKayit
 
CREATE PROC NOTLAR_SonKayit
AS
SELECT TOP 1 YAZI FROM NOTLAR
ORDER BY ID DESC;
 
 
 
 
 

Answers (7)