Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 = "✘";
        }         
    }
}
C#

Posted
Updated 20-May-20 1:10am

1 solution

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<
C#
foreach (DataRow row in dt.Rows)
{
     if (dt.Rows[0]["LicenseType"] == "Office 365 (Plan E5)")
 
Share this answer
 

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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900