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");
}
}
What is wrong with my code? In this code I am getting data from a user through a TextBox as a Company Code, then I am comparing with a Sharepoint list. If it matches, go to next page, if not, then stay on the same page and give an error.
remove query tag from the string(query.Query) build the CAML directly from where tag