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

本文关键字:SQL 语句 代码 内部 帮助 我的 | 更新日期: 2023-09-27 18:01:04

我有两个表,我要找的是:

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;
}

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

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

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子句

中再次重复该关系

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