Hey,
I am trying to use the following code:
string connVac = "...";
SqlConnection dbConnVac = new SqlConnection(connVac);
DataSet dsInfo = new DataSet();
string sqlVac1 = "Select distinct job_name from tbl_vacancies Where (availability = 'Live')";
string sqlVac2 = "SELECT DISTINCT tbl_job_titles.body, tbl_vacancies.job_id, tbl_vacancies.job_name, " +
"tbl_vacancies.location FROM tbl_vacancies INNER JOIN tbl_job_titles ON " +
"tbl_vacancies.job_name = tbl_job_titles.name " +
"WHERE (tbl_vacancies.availability = 'Live')";
dbConnVac.Open();
SqlCommand dbVac = new SqlCommand(sqlVac1, dbConnVac);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = dbVac;
adapter.Fill(dsInfo, "Jobs");
dbVac = new SqlCommand(sqlVac2, dbConnVac);
adapter = new SqlDataAdapter();
adapter.SelectCommand = dbVac;
adapter.Fill(dsInfo, "JobDetails");
dbConnVac.Close();
int ocount = 0;
int icount = 0;
bool display = false;
string jobname = "";
for (ocount = 0; ocount < dsInfo.Tables["Jobs"].Rows.Count; ocount++)
{
Label2.Text += "<div id='vacancies'><p><strong>" + dsInfo.Tables["Jobs"].Rows[ocount]["job_name"].ToString() + "</strong></p>";
jobname = dsInfo.Tables["Jobs"].Rows[ocount]["job_name"].ToString().ToLower();
for (icount = 0; icount < dsInfo.Tables["JobDetails"].Rows.Count; icount++)
{
if (jobname == dsInfo.Tables["JobDetails"].Rows[icount]["job_name"].ToString().ToLower())
{
if (display == false)
{
Label2.Text += "<p>" + dsInfo.Tables["JobDetails"].Rows[icount]["body"].ToString() + "</p><br/>" +
"<span>" + dsInfo.Tables["JobDetails"].Rows[icount]["location"].ToString() + "</span><BR>";
display = true;
}
else
{
Label2.Text += "<span>" + dsInfo.Tables["JobDetails"].Rows[icount]["location"].ToString() + "</span><BR>";
display = false;
}
}
}
Label2.Text += "</div>";
}
To Iterate through a row through the database, check to see if it has been displayed, and if not then display it.
If you look on this page you will see what is happening:
http://kidsunlimited.co.uk/vacancies_test.aspx
If you look at the job called Cook you will see that the location is being displayed first and then the body, and then the location again…
So it displays like this:
Cambridge Science park - Cambridge - Cambridgeshire
“We are looking for a Cook…”
Broadgreen - Liverpool - Merseyside
Now i need it to display the location which is this:
Cambridge Science park - Cambridge - Cambridgeshire
Broadgreen - Liverpool - Merseyside
AFTER the body…
Can i do this?