Click here to Skip to main content
16,019,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to check if certain values exist in a table based on ID in the DetailView. For instance, i have 4 fields in the backend table:

ID Approved1 Approved2 Approved3

A) First i want to check if Approved1, Approved2, Approved3 fields are not null, meaning the values are either Yes or No for all the 3 fields. If anyone of them is null or blank then i want to quit the function

B) If all Approved(*) fields have a value of "YES" based on the selected ID in the DetailView then i want to call some function;
C) If one of the Approved fields is "NO" then i want to call some other function. can someone help and show me some example? thanks

this is what i have so far:
C#
private void CheckData()
    {

        
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
        SqlDataAdapter da = new SqlDataAdapter("SELECT ID, Approved1, Approved2, Approved3", con);
        DataTable dt = new DataTable();
        da.Fill(dt);
        
    }
Posted

1 solution

You can do something like below:

C#
foreach(var row in dt.Rows){
    string id = row["id"];
    string app1 = row["Approved1"];
    string app2 = row["Approved2"];
    string app3 = row["Approved3"];

    if(string.IsNullOrEmpty(app1) || string.IsNullOrEmpty(app2) || string.IsNullOrEmpty(app3))
        return;
    
    if(app1.ToLower()=="yes" && app2.ToLower()=="yes" && app3.ToLower()=="yes")
        YesFunction();
    else
        NoFunction();
}


Haven't tested the code.. so, you might have to make some changes... Hope this helps..
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900