(变量名)既不是DataColumn也不是表Table的DataRelation

时间:2012-08-01 13:24:11

标签: asp.net sql

这是我从数据库中获取数据的代码(我使用数据集):

public DataSet getJobVacancy(GetJobVacancyData data)
{
    try
    {
        string _SPName  = "dbo.SearchJob";
        SqlParameter[] sqlParam = new SqlParameter[3];
        sqlParam[0] = new SqlParameter("@Keyword", SqlDbType.VarChar, 25);

        if(data.Keyword == null || data.Keyword == "")
            sqlParam[0].Value = DBNull.Value;
        else
            sqlParam[0].Value = data.Keyword;

        sqlParam[0].Direction = ParameterDirection.Input;
        sqlParam[1] = new SqlParameter("@LocationID", SqlDbType.SmallInt);

        if(data.LocationID == null)
            sqlParam[1].Value = DBNull.Value;
        else
            sqlParam[1].Value = data.LocationID;

        sqlParam[1].Direction = ParameterDirection.Input;
        sqlParam[2] = new SqlParameter("@ExperienceYears", SqlDbType.TinyInt);

        if(data.ExperienceYears == null)
            sqlParam[2].Value = DBNull.Value;
        else
            sqlParam[2].Value = data.ExperienceYears;

        sqlParam[2].Direction = ParameterDirection.Input;

        return SqlHelper.ExecuteDataset(SystemConfiguration.AMDP2_ConnectionString,
                                        CommandType.StoredProcedure,
                                       _SPName,
                                       sqlParam);

    }
    catch (Exception ex)
    {
        throw ex;
    }
}

这是我的二传手:

public string JobVacancyID { get; set; }
public string PostingDate { get; set; }
public string ClosingDate { get; set; }
public string Position { get; set; }
public string Location { get; set; }
public string Keyword { get; set; }
public string LocationID { get; set; }
public string ExperienceYears { get; set; }

这是我的Repeater的数据绑定:

protected void rptJob_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || 
        e.Item.ItemType == ListItemType.AlternatingItem)
    {
        DataRowView data = (DataRowView)e.Item.DataItem;

        Literal ltrDatePosted = (Literal)e.Item.FindControl("ltrDatePosted");
        Literal ltrClosingDate = (Literal)e.Item.FindControl("ltrClosingDate");
        LinkButton lbtnPosition = (LinkButton)e.Item.FindControl("lbtnPosition");
        Literal ltrLocation = (Literal)e.Item.FindControl("ltrLocation");
        Literal ltrExpYears = (Literal)e.Item.FindControl("ltrExpYears");
        Literal ltrJobVacancyID = (Literal)e.Item.FindControl("ltrJobVacancyID");

        ltrDatePosted.Text = data["PostingDate"].ToString();
        ltrClosingDate.Text = data["ClosingDate"].ToString();
        lbtnPosition.Text = data["Position"].ToString();
        ltrLocation.Text = data["LocationName"].ToString();
        ltrExpYears.Text = data["ExperienceYears"].ToString();
        ltrJobVacancyID.Text = data["JobVacancyID"].ToString(); //this is where the error occured
    }
}

这是我的sql查询/存储过程(我已经运行了这个查询,并且结果中有JobVacancyID列):

BEGIN
SELECT JobVacancyID, PostingDate, ClosingDate, Position, b.LocationName, ExperienceYears FROM TRJobVacancy a
JOIN LTLocation b on a.LocationID = b.LocationID    
WHERE Position LIKE '%'+ COALESCE(@Keyword,Position) + '%' AND COALESCE(@LocationID, a.LocationID) = a.LocationID AND COALESCE(@ExperienceYears,ExperienceYears)  = ExperienceYears

我得到的错误是:“ JobVacancyID既不是DataColumn也不是表格的DataRelation

令人困惑的事实是: 1.它只在数据[“JobVacancyID”]中给出错误,其他是平滑的。 2.我想我没有一个名为Table的表(错误说这个) 谢谢:D

2 个答案:

答案 0 :(得分:2)

SORRY ALL .....我只是错过输入变量..它需要大约3个小时来实现它@ _ @

答案 1 :(得分:1)

我遇到了同样的问题,但除了设置类型外,我也错过了几个数据域值。主要在GridTemplateColumn列上。