一个DataRelation这是我从数据库中获取数据的代码(我用的数据集):(变量名)既不是一个DataColumn,也不是表表
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; }
这一个是我的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.我想我没有一个名为表(错误说这个) 感谢:D
**从不**写'抛出;'。摆脱那个“catch”块。 – SLaks 2012-08-01 13:28:06
同意。如果你只是抛出异常,那么try/catch是不必要的。此外,在设置'ltrJobVacancyID.Text'之前,请通过执行'data.Table.Columns.Contains(“JobVacancyID”)'来确保列存在。我想知道是否可能有错别字。错误中实际说的是什么?[变量名称]? – SPFiredrake 2012-08-01 13:35:35
完成,但错误仍然存在... 感谢:D – 2012-08-01 13:36:34