Click here to Skip to main content
15,908,254 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi. I take one form for displaying all data with insert,update,delete but i found error in this code my BindGrid() is

but i found error in this "return dTable;"

C#
private DataTable BindGrid()
      {
        PersonBAL3 p = new PersonBAL3();
        try
        {
          DataTable dTable = p.Load();
          GridView1.DataSource = dTable;
          GridView1.DataBind();
        }
        catch (Exception ee)
        {
          lblMessage.Text = ee.Message.ToString();
        }
        finally
        {
          p = null;
        }
        return dTable;
     }

[Edit: added pre tag]
Posted
Updated 29-May-11 4:35am
v3
Comments
thatraja 29-May-11 10:36am    
What's the error message? Include the error message in your question always. It will save our time.
vivekal 29-May-11 10:40am    
Error The name 'dTable' does not exist in the current context
thatraja 29-May-11 10:48am    
Oops OriginalGriff beat me to it, If you posted the error message at first I would been answered before him. :(
Wonde Tadesse 29-May-11 12:49pm    
This is lack of basic programming skill.

1 solution

Move the declaration of "dTable" outside the try block:
private DataTable BindGrid()
      {
        PersonBAL3 p = new PersonBAL3();
        DataTable dTable = null;
        try
        {
          dTable = p.Load();
          GridView1.DataSource = dTable;
          GridView1.DataBind();
        }
        catch (Exception ee)
        {
          lblMessage.Text = ee.Message.ToString();
        }
        finally
        {
          p = null;
        }
        return dTable;
     }
 
Share this answer
 
Comments
thatraja 29-May-11 10:48am    
You beat me to it. 5!
Wonde Tadesse 29-May-11 12:49pm    
5+
FJD.DEETLEFS 30-May-11 5:55am    
High 5 !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900