Click here to Skip to main content
14,865,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This code related to Gridview when retun table give error


C#
protected void imgBtnSearch_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                BindGrid();
            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.Message;
            lblMessage.Visible = true;
        }
    }

private Table GetData()
    {
        SearchParivarDO objSearchParivarDO = new SearchParivarDO();
        SearchParivarBLL objSearchParivarBLL = new SearchParivarBLL();
        DataTable dt = new DataTable();
        int Language;
        //objSearchParivarDO.FatherHusbandName=txt
        //objSearchParivarDO.WardID=int.Parse(txtWard.Text);
        //objSearchParivarDO.HouseNo = txtHouse.Text.Trim();

        objSearchParivarDO.MemberName = txtName.Text.Trim();

        if (Session["MyCulture"].ToString() == "en-GB")
            Language = 1;
        else
            Language = 2;

        if (txtWard.Text.Trim() != string.Empty)
        {
            objSearchParivarDO.WardID = int.Parse(txtWard.Text.Trim());
        }
        if (txtHouse.Text.Trim() != string.Empty)
        {
            objSearchParivarDO.HouseNo = txtHouse.Text;
        }
        //if (txtBirthDateFrom.Text.Trim() != string.Empty)
        //{
        //    objSearchParivarDO.BirthDateFrom = DateTime.Parse(txtBirthDateFrom.Text.Trim()).ToString("dd/MMM/yyyy", BasePage.Culture);
        //}
       // objSearchParivarDO.ChildName = txtChildName.Text.Trim();

        return  objSearchParivarBLL.SearchParivarDetails(objSearchParivarDO, Language).Tables[0];    
    }
    private void BindGrid()
    {
        DataTable dt = GetData();

        if (dt.Rows.Count == 0)
        {
            dt.Rows.Add(dt.NewRow());
            gvParivarDetails.DataSource = dt;
            gvParivarDetails.DataBind();
            int ColumnCount = gvParivarDetails.Rows[0].Cells.Count;
            gvParivarDetails.Rows[0].Cells.Clear();
            gvParivarDetails.Rows[0].Cells.Add(new TableCell());
            gvParivarDetails.Rows[0].Cells[0].ColumnSpan = ColumnCount;
            gvParivarDetails.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
            gvParivarDetails.Rows[0].Cells[0].Text = "No Record Found";
            gvParivarDetails.Rows[0].Cells[0].CssClass = "message";
        }
        else
        {

            gvParivarDetails.DataSource = dt;
            gvParivarDetails.DataBind();
        }
        if (Session["UserID"] == null)
        {
            gvParivarDetails.Columns[10].Visible = false;
        }

    }


The error is on the line:
C#
return  objSearchParivarBLL.SearchParivarDetails(objSearchParivarDO, Language).Tables[0];
at the end of the GetData method


[edit]Code block sorted out - OriginalGriff[/edit]
Posted
Updated 30-Apr-13 23:15pm
v2

1 solution

Well, yes...you are trying to return a DataTable from a method declared as returning a Table.
Change
C#
private Table GetData()

To
C#
private DataTable GetData()
   
Comments
Faizymca 1-May-13 5:28am
   
Thanx..Sir Now error are removed
OriginalGriff 1-May-13 5:36am
   
You're welcome!

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