Becky Bloomwood

Becky Bloomwood

  • NA
  • 119
  • 285.4k

Binding data from SQL Server to grid view.

Jan 23 2011 9:56 AM

Hi, I am developing a web application project. For now I am doing the search function whereby I am required to call data stored in MS SQL Server 2008 and bind to grid View. In the Common_DDL page, there is a class that is responsible for connecting to the database.
I input in my code as followed:
 

public DataSet Get_ItemCatalogueRecords()
{
SqlCommand cmd_ItemCatalogue = new SqlCommand();
cmd_ItemCatalogue.CommandText =
"[VRM].[GET_ItemCatalogueRecords]";
cmd_ItemCatalogue.CommandType =
CommandType.StoredProcedure;
cmd_ItemCatalogue.Parameters.Clear();
DataSet ds_ItemCatalogue = getDataSet(cmd_ItemCatalogue);-->Sometimes this sentence is in error state.
return ds_ItemCatalogue;
}

This is the code that I input in the aspx.cs:
 
 

private void BindGrid(bool Reload)
        {
            DataTable dtItemCatalogueRecords = null;
          
            if (Reload)
            {
                dtItemCatalogueRecords = GET_ItemCatalogueRecords().Tables[0];
               
            }
            else
            {
                //retrieve the ViewState object datatable
                dtItemCatalogueRecords = ViewState[viewStateGVName] as DataTable;
              dtItemCatalogueRecords.DefaultView.Sort = ViewState[this.ToString() +
                  "_SortExpression"].ToString() + " " +
                  ViewState[this.ToString() + "_SortDirection"].ToString();
            }
            if (dtItemCatalogueRecords != null)
            {
                if (dtItemCatalogueRecords.Rows.Count > 0)
                {
                    ViewState[viewStateGVName] = dtContractTemplateRecords;
                    gvItemCat.DataSource = ViewState[viewStateGVName];
                    gvItemCat.AllowSorting = true;
                    gvItemCat.DataBind();
                   
                }
                else
                {
                    dtItemCatalogueRecords.Rows.Add(dtItemCatalogueRecords.NewRow());
                    ViewState[viewStateGVName] =dtItemCatalogueRecords;
                    gvItemCat.DataSource = ViewState[viewStateGVName];
                    gvItemCat.AllowSorting = false;
                   gvItemCat.DataBind();
                    int TotalColumns = gvItemCat.Rows[0].Cells.Count;
                    gvItemCat.Rows[0].Cells.Clear();
                    gvItemCat.Rows[0].Cells.Add(new TableCell());
                    gvItemCat.Rows[0].Cells[0].ColumnSpan = TotalColumns;
                    gvItemCat.Rows[0].Cells[0].Text = "No Record Found";
                }
            }
        }
However the error states:  name 'GET_ItemCatalogueRecords' does not exist in the current context. However i did define it. Thanks.


Answers (7)