1

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

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;
    }
}

这是我的 setter-getter :

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; }

这是我的中继器的数据绑定:

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 也不是表 Table 的 DataRelation

令人困惑的事实是: 1. 它只在 data["JobVacancyID"] 处出错,其他的都很顺利。2. 我想我没有一个名为 Table 的表(错误是这样说的)谢谢 :D

4

2 回答 2

2

抱歉……我只是想念输入变量……花了大约 3 个小时才意识到它@_@

于 2012-08-02T16:10:11.350 回答
1

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

于 2014-04-15T01:26:54.963 回答