0

I have got the following error message when I'm trying to search things from Datagridview using MyDataGridview as a DataTable shown below:

the error:

Object reference not set to an instance of an object.

The Search Code:

 private void txtSearch_TextChanged(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        string filterField = "pname";
        dt = (DataTable)dgvpd.DataSource;          
        dt.DefaultView.RowFilter = string.Format("[{0}] LIKE '%{1}%'", filterField, txtSearch.Text);
    }

The error message points on this line

 dt.DefaultView.RowFilter = string.Format("[{0}] LIKE '%{1}%'", filterField, txtSearch.Text);
Nur Selam
  • 451
  • 1
  • 4
  • 14
  • [What is a `NullReferenceException` and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Soner Gönül Jul 22 '15 at 07:43
  • I have seen it, but may be different with my own code context? – Nur Selam Jul 22 '15 at 08:09
  • I think you have got the possible symptom, can you try to resolve it by providing the suggested code, just edit it the above. Thanks in Advance. – Nur Selam Jul 27 '15 at 07:32

0 Answers0