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

そして、これは私のセッターゲッターです:

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でも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 に答える