C# .NET - System.NullReferenceException: Object reference not set to an instance of an object. ERROR

Asked By Gokhan Metepe on 26-Sep-12 07:04 AM
I am trying to read data with this codes. I can see them on DataGridView but during Loading im am gettng this error.
What shall i do ?

Here is the code;

SqlDataAdapter DTMUA3 = new SqlDataAdapter("sp_tumSoruEkler", ZOlG8CONS);
      SqlCommandBuilder CommandSette3 = new SqlCommandBuilder(DTMUA3);
      DataTable TableSette3 = new DataTable();
      TableSette3.Locale = System.Globalization.CultureInfo.InvariantCulture;
      DTMUA3.Fill(TableSette3);
      bs3.DataSource = TableSette3;
      dgv3.ReadOnly = true;
      dgv3.DataSource = bs3;
      dgv3.Font = new Font("Arial", 8, FontStyle.Regular);
      dgv3.RowHeadersVisible = false;
      dgv3.Columns[0].HeaderText = "Dosya Adı";
      dgv3.Columns[1].HeaderText = "Soru Ana Kodu";
      dgv3.Columns[2].HeaderText = "Soru Kodu";
      dgv3.Columns[0].Width = 150;
      dgv3.Columns[1].Width = 50;
      dgv3.Columns[2].Width = 50;
      dgv3.AllowUserToAddRows = false;

Here is the Sp;

USE [****]
GO
/****** Object:  StoredProcedure [dbo].[sp_tumSoruEkler]    Script Date: 26.09.2012 13:55:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[sp_tumSoruEkler]
AS
Select FileName, SoruAnaKodu, SoruKodu From SoruEkleri
Jitendra Faye replied to Gokhan Metepe on 26-Sep-12 08:31 AM
This problem comes when you try to get or set values from any  null object.

so before fetching or setting value first check that is it null or what.

check for object where you are getting error.
Gokhan Metepe replied to Jitendra Faye on 26-Sep-12 10:28 AM
Thanks for your reply.
There are not any null values. But two columns datatype int. Is it a reason for this error?
Jitendra Faye replied to Gokhan Metepe on 27-Sep-12 01:26 AM
No that can't be the reason. It is better to put break point in your code and debug it. You will get exact line where you are getting error.
Gokhan Metepe replied to Jitendra Faye on 28-Sep-12 06:11 AM
Thanks, i will try.