locked
checking the value in a table. RRS feed

  • Question

  • User355715116 posted

    let  I have a table called test and another table called  testTwo.

    I got a value (row) from table test which is rollNo.
    Now i want to check and compare that if there is any row called  rollNo exists in my  testTwo table. 

    How can i do this in asp.net? Thanks. 

    I am adding some sample code here to get the concept that what i am trying to do. 

    int? rollNO = null; 
    
    if (((DataRowView)e.Item.DataItem).Row["rollNO"].ToString() != null && ((DataRowView)e.Item.DataItem).Row["rollNO"].ToString().Trim().Length > 0)
                    {
                        rollNO= Int32.Parse(((DataRowView)e.Item.DataItem).Row["rollNO"].ToString());
                    }
    
    
    
    
    
    
    if (((DataRowView)e.Item.DataItem).Row["IsActiveStatus"].ToString() == "False")
                    {
                        if (here i want to check that if rollNO row exists in testTwo table)
                        {
                            item.CssClass = "Green" + " rgRow";
                        }
                        else
                        {
                            item.CssClass = "Red" + " rgRow";
                        }
                    }

    Thursday, June 11, 2020 4:15 PM

Answers

  • User475983607 posted

    Usually this type of logic is handled in SQL with a basic SQL JOIN or SELECT.  The result set is passed to the data bound control where you can do with the result set as you please.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2020 5:24 PM
  • User-939850651 posted

    Hi, mazharul007

    According to your description, do you want to determine whether a column is included in the data set?

    If so, I think you maybe use :

    private void ContainColumn(string columnName, DataTable table)
    {
        DataColumnCollection columns = table.Columns;        
        if (columns.Contains(columnName))
        {
           ....
        }
    }

    More details, please refer DataColumnCollection.Contains(String) Method.

    Before this, I think you have got the data of the testTwo table.

    Hope this can help you.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 12, 2020 3:27 AM

All replies

  • User475983607 posted

    Usually this type of logic is handled in SQL with a basic SQL JOIN or SELECT.  The result set is passed to the data bound control where you can do with the result set as you please.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 11, 2020 5:24 PM
  • User-939850651 posted

    Hi, mazharul007

    According to your description, do you want to determine whether a column is included in the data set?

    If so, I think you maybe use :

    private void ContainColumn(string columnName, DataTable table)
    {
        DataColumnCollection columns = table.Columns;        
        if (columns.Contains(columnName))
        {
           ....
        }
    }

    More details, please refer DataColumnCollection.Contains(String) Method.

    Before this, I think you have got the data of the testTwo table.

    Hope this can help you.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 12, 2020 3:27 AM