Hey,
I am trying to use this code:
string connVac = "Database connection...";
SqlConnection dbConnVac = new SqlConnection(connVac);
DataSet dsInfo = new DataSet();
string sqlVac1 = "Select distinct job_name from tbl_vacancies Where (availability = 'Live')";
string sqlVac2 = "SELECT job_id, job_name,location, (location) AS region, " +
"(SELECT TOP (1) job_id FROM tbl_vacancies WHERE (availability = 'Live') AND (job_name = tbl_vacancies_1.job_name)) AS job_id " +
"(SELECT TOP (1) details FROM tbl_vacancies WHERE (availability = 'Live') AND (job_name = tbl_vacancies_1.job_name)) AS theDetails " +
"FROM tbl_vacancies AS tbl_vacancies_1 " +
"WHERE (availability = 'Live') " +
"GROUP BY job_id, job_name, region, location";
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;
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())
{
Label2.Text += "<div class='vacancy-info'><p>" + dsInfo.Tables["JobDetails"].Rows[icount]["theDetails"].ToString() + "</p><br/>" +
"<span>" + dsInfo.Tables["JobDetails"].Rows[icount]["region"].ToString() + "</span>" +
"</div>";
}
}
Label2.Text += "</div>";
}
And i get this error:
Incorrect syntax near the keyword ‘AS’.
What i am trying to do is SELECT details of a job and also SELECT which region the job is in.
I currently have this:
http://kidsunlimited.co.uk/vacancies.aspx
But i need to change it so it shows the Job name, details and then the regions…
What am i doing wrong? Can anyone help?
Thanks