S

S

  • NA
  • 381
  • 97.5k

Data Retrieval from DB and Displaying...

Apr 16 2013 10:14 AM
Hello 

Given the following code:-

 protected void Button2_Click(object sender, EventArgs e)
        {
            var search = TextBox2.Text;


            Database1Entities d = new Database1Entities();
            var query = from s in d.Customers
                        where s.Customername == search
                               select s;


            foreach (Customer c in query)
            {
                TextBox3.Text = c;
            }

What I want to achieve is a search given a particular name.

The local search variable is being passed into a L2S Query, im then looping through the records in the DB and then trying to assign the result set\return values to TextBox3 however I get a casting\conversion error due to the fact Text is of type string and my return value is of type Customer? yet, the Customername column in my DB is of type string or more accurately nvarchar?

Regards
Steven

Answers (2)