需要帮助来修复我的内部联接SQL语句和C#代码

时间:2015-07-05 20:30:28

标签: c# asp.net sql-server

我有两张桌子,我正在寻找的是:

JobApplic表包含:

ApplicNum, 
JobNum, 
UID "this is the employer", 
Jobtitle, 
AplicUID " this is job seeker" 

CVs表包含:

CVNum, 
UID (here in this table is the job seeker) , 
FN, 
LN, 
etc.... 

声明它是这样的,但我不是那么专业,以正确的方式写作:

select 
from [JobApplic] ApplicNum, JobNum, UID, Jobtitle, AplicUID 
where 
     UID 
into table JobApplic = session["UsrNme"], 
inner join table [CVs] UID,FN, LN, ... 
Where UID into table CVs = ApplicUID into table JobApplic"    

此代码的平均值是,当雇主进入他的账户时,他将能够看到所有申请人的简历,其中申请的是雇主发布的职位。

protected void ViewapplCV_Click(object sender, EventArgs e)
{
    if (Session["UsrNme"] != null)
    {
        using (SqlConnection AppCVsSQLCon = new SqlConnection(sc))
        {
            AppCVsSQLCon.Open();

            SqlDataAdapter ApplCVsDAADP = new SqlDataAdapter(@"
               SELECT AD.[ApplicNum], AD.[JobNum], AD.[UID], AD.[Jobtitle],
                      AD.[AplicUID], UI.[UID], UI.[FN], UI.[LN] 
               FROM [JobApplic] AS AD JOIN CVs AS UI ON AD.[UID] = UI.[UID] 
               WHERE AD.UID = @UID AND AD.AplicUID = UI.UID", sc);

            var use = Session["UsrNme"];

            ApplCVsDAADP.SelectCommand.Parameters.AddWithValue("@UID", use);

            DataSet dsApplCVs = new DataSet();

            ApplCVsDAADP.Fill(dsApplCVs);

            showapplicforemployrLV.DataSource = dsApplCVs.Tables[0];
            showapplicforemployrLV.DataBind();
        }
    }
    else
    {
        // Your Session key could not be found, consider displaying an error
    }

    MultiView1.ActiveViewIndex = 12;
}

2 个答案:

答案 0 :(得分:0)

如果我正确理解了这些表之间的关系,那么查询应该是

SqlDataAdapter ApplCVsDAADP = new SqlDataAdapter(@"
   SELECT AD.[ApplicNum],AD.[JobNum],AD.[UID],AD.[Jobtitle],
          AD.[AplicUID],UI.[UID],UI.[FN],UI.[LN] 
   FROM [JobApplic] as AD JOIN CVs as UI ON AD.[AplicUID] = UI.[UID] 
   WHERE AD.UID = @UID", sc);

你说的是第一个表 AplicUID "这是求职者" ,在第二个表中UID (此表在此表中是求职者)因此您需要在这两个字段之间建立连接,并且无需在WHERE子句中再次重复关系

答案 1 :(得分:0)

SELECT JA.ApplicNum [ApplicationNo] ,JA.JobNum [JobNo] ,JA.UID [EmployerID] ,JA.JobTitle [JobTitle] ,JA.AplicUID [ApplicantID] ,CurVit.FN [Applicants First Name] ,CurVit.LN [Applicants Last Name] FROM JobApplic as JA INNER JOIN CV AS CurVit ON JA.AplicUID = CV.UID WHERE JA.UID = ''-- WHERE THE USERID OF THE EMPLOYER/USER ACCESSED TO HIS/HER ACCOUNT