在ASP.Net中使用C#检查表中的列值 [英] check column values in a table using C# in ASP.Net

查看:77
本文介绍了在ASP.Net中使用C#检查表中的列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据DetailView中的ID检查表中是否存在某些值.例如,我在后端表中有4个字段:

ID已批准1已批准2已批准3

A)首先,我想检查Approved1,Approved2,Approved3字段是否不为空,这意味着所有3个字段的值都是是"或否".如果其中任何一个为null或为空,那么我想退出该功能

B)如果所有的(*)字段都基于在DetailView中选择的ID的值为是",那么我想调用某个函数;
C)如果批准"字段之一为否",那么我想调用其他功能.有人可以帮我看看一些例子吗?谢谢

这是我到目前为止的内容:

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:

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);
        
    }

推荐答案

您可以执行以下操作:

You can do something like below:

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..


这篇关于在ASP.Net中使用C#检查表中的列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆