2016-02-19 73 views
-1

我有一个方法,检查返回true/false取决于列是否为null或不在sql表中。我如何检查我的sql表中的列是否为空使用c#

我该如何去检查某个列是否在我的c#方法中的sql db中为空。

public bool CheckQuoteStatus(string user) 
{ 
    //checking against the sql db in table where userid=user if column 
     QUOTESTATUS=NULL then return false otherwise return true 

} 

这里是如何连接到SQL数据库

static SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()); 
+1

你在使用连接到数据库?根据您使用的框架,可以以不同的方式返回空值。 – Dispersia

+0

编辑我的问题,谢谢 –

回答

-1

以及即时通讯,如果你想查询字符串== null,那么用户该代码。

public bool CheckQuoteStatus(string user) 
{ 
    return (user == null);  
} 
0

那么,如果该值从查询返回的,你可以对空值使用DbNull.Value

return (user == DbNull.Value ? true : false); 
+0

我将如何查询并将结果保存在变量中? –

+0

这与返回用户== DbNull.Value btw:P相同。三元不需要 – Dispersia

+0

:p它应该是'return(user == DbNull.Value?false:true)'的另一种方式;'' –

相关问题