M A Hossan M A Hossan - 2 days ago 4
C# Question

Code Always goes to if statement

Database column value comparisons with local variable but code dud not produce expected result here is my code

public partial class PL_WebForm2 : System.Web.UI.Page
{

int i = 600;
int j = 700;
int k = 800;
}

SqlCommand cmd = new SqlCommand("SELECT Credit_Score FROM Credit_Score WHERE Account_Number = @Account_Number", cn);
//cn.Open();
cmd.Parameters.AddWithValue("Account_Number", lblAccountNumber.Text);
var value = cmd.ExecuteScalar();
var da = new SqlDataAdapter(cmd);
DataTable tbl = new DataTable();
da.Fill(tbl);

if (tbl.Rows.Count == 0)
{
Label1.Text = ("Account is exist Under this Name");

}
else if ((Convert.ToDouble(i) < Convert.ToDouble(value)))
{

Label1.Text = "Application Successful We can offer you 5000 Pund ";
}
else if ((Convert.ToDouble(j) < Convert.ToDouble(value)))
{

Label1.Text = "Application Successful We can offer you 6000 Pund ";
}
else if ((Convert.ToDouble(k) < Convert.ToDouble(value)))
{
[enter image description here][1]
Label1.Text = "Application Successful We can offer you 8000 Pund ";
}


else
{

Label1.Text = "Application Unccessful";


}
}


I upload the database record images. please find the image .thanks in advance.
Image

Answer

I find it quite difficult to understand what your issue is sadly BUT if my powers of deductive reasoning are correct it looks like all you need to is make your else if statements a "between" so:

    if (tbl.Rows.Count == 0)
    {
        Label1.Text = ("Account  is exist Under this Name");

    }
    else if ((Convert.ToDouble(i) < Convert.ToDouble(value)) && (Convert.ToDouble(value) <= Convert.ToDouble(j)))
    {

        Label1.Text = "Application Successful We can offer you 5000 Pund ";
    }
    else if ((Convert.ToDouble(j) < Convert.ToDouble(value)) && (Convert.ToDouble(value) <= Convert.ToDouble(k)))
    {

        Label1.Text = "Application Successful We can offer you 6000 Pund ";
    }
    else if ((Convert.ToDouble(k) < Convert.ToDouble(value)))
    {
        Label1.Text = "Application Successful We can offer you 8000 Pund ";
    }
    else
    {
        Label1.Text = "Application Unccessful";
    }
Comments