Question

Okay here is my code

protected void TextBox1_TextChanged(object sender, EventArgs e)
{

    if (bll.MainEnq_Stu_Name(en) != null)
    {
        Label9.Text = bll.MainEnq_Stu_Name(en).ToString();
    }
    else
    {
        Label9.Text = "No Records Found!";
    }  
}

here is the query in the business logic layer.

  //MainEnquiry.aspx panel1
    public object MainEnq_Stu_Name(EntityLayer.Entity en)
    {
        return dll.GetSingleValue("select name from studentinfo where mobile=" + en.mainEnq_Stu_Mobile+"and dob is not null");
    }

here is the screen shot of the table in db.

now what i want to do is to add one more functionality to if iteration in my code above.

that is if mobile is null print "no records found".
and if dob is not null print "this user already exists"
Was it helpful?

Solution

You need to include columns which are required in your case its name,mobile and dob. So first do this

//MainEnquiry.aspx panel1
public object MainEnq_Stu_Name(EntityLayer.Entity en)
{
    return dll.GetSingleValue("select name,mobile,dob from studentinfo where mobile=" + en.mainEnq_Stu_Mobile+"and dob is not null");
}

Then just else if conditions in your code. Hope you can go from here.

OTHER TIPS

You can use a case statement in your SQL select statement. But I don't know if the following is what you want to do. Do you want to return the three columns or just one?

    //MainEnquiry.aspx panel1
    public object MainEnq_Stu_Name(EntityLayer.Entity en)
    {
        return dll.GetSingleValue("select case when mobile is null then 'no records found' when dob is null then 'this user already exists' else name end from studentinfo where mobile=" + en.mainEnq_Stu_Mobile+"and dob is not null");
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top