tags:

views:

75

answers:

3

hi

I want to Search in my Table. I write follow Code :

var w = from act in Movie_List.Actors
                     where act.Actor_Name == Snametxt.Text
                     select new {act.Actor_Name};
Acttxt.Text= w.SingleOrDefault().Actor_Name;

this code work only for FIRST search and when I want to search again , appear exception .

Exception :

Object reference not set to an instance of an object.

I don't know how to solve this problem.

help me please.

A: 
  1. What is the exception?
  2. Changing the primary key is really bad, mmkay, k.
leppie
this is exception : " Sequence contains no elements "
mohammad reza
Use SingleOrDefault in that case.
leppie
I use SingleOrDefault now and appears this exception :" This causes two bindings in the collection to bind to the same property.Parameter name: binding "
mohammad reza
I have not come across that exception yet. Perhaps a google will help.
leppie
The problem in your code is outside of the scope of the snippet you posted. You will need to give us a bit more information on "Movie_List", as well as how it is databound.
David Anderson
A: 

I could solve problem finally.

you must remove binding after binding data .

            try
            {
                Acttxt.DataBindings.RemoveAt(0);
            }
            catch
            {

            }

before bind control too database write this code for any control.

mohammad reza
A: 

you gotta first check to see if w contains any element :

var w = from act in Movie_List.Actors
                     where act.Actor_Name == Snametxt.Text
                     select new {act.Actor_Name};
if (w.Any())
   Acttxt.Text= w.SingleOrDefault().Actor_Name;
Adinochestva