How to compare a single row value with an whole column value in c#???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sri devi
    New Member
    • Sep 2010
    • 7

    How to compare a single row value with an whole column value in c#???

    Hi Frnz,
    Kindly, help me. How to compare a single row with a whole column value in C3
    For Ex:
    ROW COLUMN
    ----------------------
    SRI DEVI
    BABU
    SRI

    I want to know the first row value "SRI" is present in that column or not. If its present no work, if its not present the row[0] value will be my answer......

    Code:
     DataTable dt1 = new DataTable();
           
     for (int i = 0; i < dt1.Rows.Count; i++)
            {
                DataRow dr = dt1.Rows[i];
                for (int j = 0; j < dt1.Rows.Count; j++)
                {
                    if ((dt1.Rows[i][8].ToString()) != (dt1.Rows[j][12].ToString()))
                    {
                        string str2 = ds1.Tables[0].Rows[i][0].ToString();
                        dr["Filter-Link2a"] = str2;
                    }
                }
            }
  • mzmishra
    Recognized Expert Contributor
    • Aug 2007
    • 390

    #2
    I think you want to check if the value SRI is present in datatable or not.

    try something like this
    Code:
    DataTable dt = new DataTable();
            foreach (DataRow dr in dt.Rows)
            {
                if(string.Compare(dr["Columnname"].ToString(),"SRI",true)==0)
                   //write your logic
            }

    Comment

    • sri devi
      New Member
      • Sep 2010
      • 7

      #3
      Thanks, for your Reply......

      My Question is, I have two columns in a datatable such as "Link1" and "Link2". The Link1 and Link2 column as 10 Rows.

      I want to compare Link1 first Row with Link2's 10 rows. How?

      Kindly, give reply.....

      Thanks,
      Sri Devi

      Comment

      • mzmishra
        Recognized Expert Contributor
        • Aug 2007
        • 390

        #4
        Code:
          DataTable dt = new DataTable();
             string link1 = dt.Rows[0]["Link1 "].ToString();
                   foreach (DataRow dr in dt.Rows)
                    {
                        
                        if(string.Compare(dr["Link2"].ToString(),link1,true)==0)
                           //write your logic
                    }

        Comment

        Working...