没有从数据库存储过程中将结果导入数据集以显示gridview

时间:2017-02-03 04:14:24

标签: c# entity-framework

我有gridview,我需要通过从dropdownlist中选择值来填充数据。

为此,我试图用参数更新存储过程。我们正在使用Entity Framework数据库访问。

但是在更改存储过程后,我没有得到任何结果到gridview。

有人可以帮助我吗?

public DataView BindReport()
{
     var user = Session["currentUser"] as UserSession;

     if (user == null) 
         return null;

     var totalrows = 0;

     var result = SalesReport.GetJobseekerReportResults(user.CompanyId,ref totalrows);
     DataView ds = ToDataTable(result).DefaultView;

     if (ViewState["SortExpr"] != null)
            ds.Sort = ViewState["SortExpr"].ToString();

     RowCount = totalrows;
     dataTable = new DataTable();
     dataTable = ds.ToTable();

     return ds;
}

private void InitializePageSize(GridView gridView)
{
    var user = Session["currentUser"] as UserSession;

    if (user == null) 
        return;

    var pageSize = GridController.GetGridSizeForUser(user.UserId, gridView.ID, user.CompanyId);

    if (pageSize == null) 
        return;

    gridView.PageSize = (int)pageSize.page_size;
    ddlSkillPageCount.SelectedValue = gridView.PageSize.ToString(CultureInfo.InvariantCulture);
    gridView.DataBind();
}

public static List<JobseekerReport_Result> GetJobseekerReportResults(long companyid,  ref int tototalrows)
{
    var context = new NavDataEntities();
    List<JobseekerReport_Result> result = null;

    try
    {
        context.Database.Connection.Open();

        result = context.JobseekerReport(companyid).ToList();
    }
    catch (Exception)
    {
    }
    finally
    {
        context.Database.Connection.Close();
    }

    return result;
}

public virtual ObjectResult<JobseekerReport_Result> JobseekerReport(Nullable<long> cmpid)
{
    var cmpidParameter = cmpid.HasValue ?
            new ObjectParameter("cmpid", cmpid) :
            new ObjectParameter("cmpid", typeof(long));

    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<JobseekerReport_Result>("JobseekerReport", cmpidParameter);
}

2 个答案:

答案 0 :(得分:0)

private void InitializePageSize(GridView gridView)
{
    var user = Session["currentUser"] as UserSession;
    if (user == null) return;
    var pageSize = GridController.GetGridSizeForUser(user.UserId, gridView.ID, user.CompanyId);
    if (pageSize == null) return;
    gridView.PageSize = (int)pageSize.page_size;
    ddlSkillPageCount.SelectedValue = gridView.PageSize.ToString(CultureInfo.InvariantCulture);
    DataSet ds =  BindReport(); /// Added these two lines.
    gridView.DataSource = ds; ///
    gridView.DataBind();
}

答案 1 :(得分:0)

我得到了结果。现在gridview在选择下拉列表值时填充结果。

我遇到的问题是edmx模型。什么时候我做表或存储过程中的更改。首先,我需要从解决方案中删除edmx模型,然后再次添加它。

谢谢。