Hi, Can enyone helpsme.Im new to C#.
i gt this error.
Embedded statement cannot be a declaration or labeled statement

My code is

foreach (Form form in Application.OpenForms){
                    if (form is productResults)
                      productResults pr =(productResults)form; 
}

PLZ...help me.

In line 2 you test if a form is productResults, so what do you mean by line 3?
If you get there IMHO you have a productResults form.

In line 2 you test if a form is productResults, so what do you mean by line 3?
If you get there IMHO you have a productResults form.

Oh! yes i understood. Thank you very much.

foreach (Form form in Application.OpenForms)
                {
                      productResults pr =(productResults)form; 
                    if ( pr is productResults)
                        pr.itemsGridView.DataSource = DS.Tables["product_Header"]; 
                }

But plz could you tell me what did you mean by IMHO?
I dont know whether it is silly to ask

There are no silly questions, there are only dumb answers. IMHO is just a shortcut for saying In My Humble Opinion:)

>Embedded statement cannot be a declaration or labeled statement

Error says that embedded statement must be enclosed by {}.

foreach (Form form in Application.OpenForms)
{
  if (form is productResults)
    {
     productResults pr =(productResults)form; 
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.