1

我在 asp.net 中有详细视图,从中我将数据插入到 DB.Here 我想在插入之前检查任何字段是否为空,如果为空,则不要插入,否则插入到 db 我尝试了以下代码,但是它不起作用

protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
     string unt = (string)e.Values["UNT_COD"];
     if (unt == "")
     {
         e.Cancel = true;  
     }
    }

通过这段代码我没有达到我的目的请任何人帮助我找出检查的方法

4

2 回答 2

2

您可以使用字符串函数如下

if (string.IsNullOrEmpty(e.Values["UNT_COD"]))
{

}
else
{
}
于 2013-03-21T10:59:37.217 回答
0
string unt = e.Values["UNT_COD"]+"";
 if (unt == "")
 {
     e.Cancel = true;  
 }
于 2013-03-21T11:02:24.347 回答