Last post Dec 23, 2016 05:05 AM by msimo
Dec 15, 2016 05:12 AM|msimo|LINK
In below code what i am trying to do is if the user select a value from one of those two DDL then code suppose to show him the result even if he did not select any value from 2nd DDL. But the problem is the code moving to 2nd part of code were it showing
the message: " Sorry but there are no applicants "
protected void EmplysSearchBtnN_Click(object sender, EventArgs e)
HttpCookie cookie = Request.Cookies.Get("Location");
using (SqlConnection EmplysSearchcon = new SqlConnection(ConfigurationManager.ConnectionStrings["BeravaConnectionString"].ConnectionString))
string EmplysSrchQ = @"SELECT [CVNum], [UID], [Birthday], [Gender], [Linkden], [FN], [LN], [PersImg], [EMail], [TeleNo], [Occupt] , [PersWebsite], [WorkEx],[Educ], [SchAndCert], [Langu], [Hobbies], [citiz], SUBSTRING([PerInfo],1,40) as PerInfo From CVs Where 1=1 ";
string condition = "";
if (ShwApplicntCountDDL.SelectedValue != "")
condition += " and citiz ='" + ShwApplicntCountDDL.SelectedValue + "'";
if (ApplicntSrchJobCategDDL.SelectedValue != "")
condition += " and Occupt ='" + ApplicntSrchJobCategDDL.SelectedItem.Text + "'";
DataTable EmplysSrchDT = new DataTable();
SqlCommand ccmd = new SqlCommand();
ccmd.Connection = EmplysSearchcon;
ccmd.CommandType = CommandType.Text;
ccmd.CommandText = EmplysSrchQ + condition;
SqlDataAdapter EmplysSrchAD = new SqlDataAdapter();
EmplysSrchAD.SelectCommand = ccmd;
//Check if datatable is having any rows which means the condition valid and it found any rows
if (EmplysSrchDT != null && EmplysSrchDT.Rows.Count > 0)
ShowJobSeekerPanel.Visible = true;
NoAplcntInUrCountPan.Visible = false;
ShowJobSeekerLV.DataSource = EmplysSrchDT;
ShowJobSeekerPanel.Visible = false;
NoAplcntInUrCountPan.Visible = true;
CountryLbl.Text = ShwApplicntCountDDL.SelectedValue;
NoAplcntInUrCountLbl.Text = "Sorry but there are no applicants ";
Dec 16, 2016 05:24 AM|Cathy Zou|LINK
From your description and code, it seems there exit logic error in your code.
ShwApplicntCountDDL is your First DDL, ShwApplicntCountDDL is your second DDL. From your code。
From your code, if EmplysSrchDT return null or EmplysSrchDT.Rows.Count<=0, the text in NoAplcntInUrCountLbl will be changed to “Sorry but there are no applicants”.
I suggest you could set breakpoint in the end of your code to see the whole work logic of your code.
Dec 19, 2016 12:59 AM|msimo|LINK
The problem is the break point into my visual studio 2015 its not working i dont know why.
Dec 23, 2016 05:05 AM|msimo|LINK
The problem is fixed, as the data type of column was nvarchar(25) where it suppose to be max