protected void btn_Submit_Click(object sender, EventArgs e)
{
lbl_EmpCode.Text = "";
SPSite newsites = SPContext.Current.Site;
SPWeb webs = newsites.OpenWeb();
SPQuery query = new SPQuery();
query.Query = string.Format ( "<Query>" +"<Where>"+ "<Eq>"+ "<FieldRef Name='Company_x0020_Code' />"+" <Value Type='Text'>"+ txt_Companycode.Text +"</Value>"+" </Eq>"+" </Where>"+" </Query>");
SPList list = webs.Lists["Companies"];
SPListItemCollection items = list.GetItems(query);
if (items.Count > 0)
{
txt_Companycode.Text = "";
Response.Redirect("Pages/ClaimAccount.aspx");
}
else
{
lbl_EmpCode.Text = "Company Code is not Matching with the Exisiting Record..!";
txt_Companycode.Text = "";
Response.Redirect("Pages/CompanyCodeCheck.aspx");
}
}
我的代码出了什么问题?在此代码中,我通过TextBox
作为公司代码从用户获取数据,然后我将与Sharepoint列表进行比较。如果匹配,请转到下一页,如果没有,则保持在同一页面上并给出错误。
答案 0 :(得分:0)
从字符串中删除查询标记(query.Query)直接从标记
构建CAML