Click here to Skip to main content
14,545,210 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a sql query which works fine and I get the data on Gridview. But when I run the second code and wants to update the html table with a tick symbol, it does not working. I always get a false result. I am trying to get LicenseType for each email ID input by the user and show the tick or cross symbol based on LicenseType.

Can someone look at the code and tell me what am I doing wrong?

What I have tried:

<pre>if (UPN.Text != string.Empty)
 {
    string mainconn = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;
    SqlConnection sqlconn = new SqlConnection(mainconn);
    sqlconn.Open();
    SqlCommand sqlcomm = new SqlCommand();
    string sqlquery = "SELECT [UPN], [LicenseType], [ZoomStatus] FROM [UserLicense].[dbo].[License] WHERE ([UPN] = @UPN)";
    sqlcomm.CommandText = sqlquery;
    sqlcomm.Connection = sqlconn;
    sqlcomm.Parameters.AddWithValue("UPN", UPN.Text);
    DataTable dt = new DataTable();
    SqlDataAdapter sda = new SqlDataAdapter(sqlcomm);
    sda.Fill(dt);
    SqlDataReader rd = sqlcomm.ExecuteReader();

    foreach (DataRow row in dt.Rows)
    {
        if (dt.Rows[0]["LicenseType"] == "Office 365 (Plan E5)")
        {
            Label1.Text = "✔";
        }
        else
        {
            Label1.Text = "✘";
        }         
    }
}

		    
Posted
Updated 20-May-20 1:10am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Take a close look: You are not comparing the value from the iterated row value, you are comparing to the value in the first row every time<
foreach (DataRow row in dt.Rows)
{
     if (dt.Rows[0]["LicenseType"] == "Office 365 (Plan E5)")
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100