从URL获取值并在select中使用它

时间:2017-11-06 20:42:11

标签: c# sql select

尝试在标题中取一个值,如果已经在DB中有一个带有这些参数的值,那么,不要在表单中显示任何内容。在理论上,它应该是有效的,但我得到的只是价值变化。 IE(0而不是1或2)。

我正在收集所有正确的值,但我没有得到要更改的值。在我的数据库中,已经有一行包含这些参数......

public int checkRef(int id, int numRef)
        {
            int chk = 0;
            base.Db.Open();
            string cuerito = "select count(*) from [JobApplication].[dbo].[tbl_references] where [userId] = @idUser and [numRef]=@testRef";
            SqlCommand command = new SqlCommand(cuerito, base.Db);
            command.Parameters.AddWithValue("@idUser",id);
            command.Parameters.AddWithValue("@testRef",numRef);
            chk = (int)command.ExecuteScalar();
            if (chk > 0)
            {
                chk = 1;
            }
            else
                chk = 2;
            return chk;
        }

protected void getCandidate()
    {
        string idCandi = Request.QueryString["id"];
        string numRef = Request.QueryString["ref"];
        ASF.HC.JobApplication.BO.Referencia refo = new ASF.HC.JobApplication.BO.Referencia();
        int numReferenciado = 0;
        int bandera = 0;
        try
        {
            numReferenciado = refo.checkRef(Int32.Parse(idCandi), Int32.Parse(numRef));
        } catch(Exception ae)
        {

        };
        if (string.IsNullOrEmpty(numRef) || numReferenciado == 2)
        {
            bandera =6;
        }
        else
        {
            bandera = Int32.Parse(numRef);
        }
        if(bandera<0 || bandera > 3)
        {
            tblGetInfo.Visible = false;
            tblThanks.Visible = true;
        }
        ASF.HC.JobApplication.BO.User dbUsuarios = new ASF.HC.JobApplication.BO.User();
        int idNum;
        if(idCandi == null)
        {
            idNum = 0;
        }
        else
        {
            idNum = int.Parse(idCandi);
        }
        String fname= dbUsuarios.GetById(idNum).FirstName +" "+ dbUsuarios.GetById(idNum).LastName;
        idCand.Text = fname;
        idCand.ReadOnly = true;
        candi.Text = numReferenciado.ToString();//here I validate the value..

    }

0 个答案:

没有答案