在C#ASP.NET中检查null或空文本和日期 [英] Check for null or empty text and date in C# ASP.NET
问题描述
为我提供检查 null或空 文本字段和日期字段的语法。
存储过程提供如下信息
检查是否为空或空日期
txt_Resp_time4.Text = SqlCmd.Parameters [@ ERESPTIME4]。Value.ToString();
检查空或空文本
txt_Response1.Text = SqlCmd.Parameters [@ ERESPONSE1]。Value.ToString();
新来的C#
谢谢
我的尝试:
检查网上的示例。
示例适用于动态声明的字符串
Provide me with the syntax to check for a null or empty text field and date field.
The stored procedure provides the information as follows
check for null or empty date
txt_Resp_time4.Text = SqlCmd.Parameters["@ERESPTIME4"].Value.ToString();
check for null or empty text
txt_Response1.Text = SqlCmd.Parameters["@ERESPONSE1"].Value.ToString();
New to C#
Thanks
What I have tried:
Checked for examples on the net .
The examples are for strings declared on the fly
推荐答案
您需要检查参数值是否已设置 - null或是否为Database NULL。以下几乎可用于任何数据库字段
You need to check if the parameter value has been set - null or is a Database NULL. The following can be used on pretty much any database field
if(SqlCmd.Parameters["@ERESPTIME4"].Value == null)
{
// the value has not been set - not initialised
}
else if(Convert.IsDBNull(SqlCmd.Parameters["@ERESPTIME4"].Value))
{
// the database contains a null value
}
else
{
// The value is not null
}
string name = SqlCmd.Parameters [@ ERESPTIME4]。值;
if(string.IsNullOrEmpty(name)== ture)
{
//结果为空或空时的代码
}
else
{
//当不为空或空时
}
string name=SqlCmd.Parameters["@ERESPTIME4"].Value;
If(string.IsNullOrEmpty(name)==ture)
{
// code when result is null or empty
}
else
{
// when not null or empty
}
这篇关于在C#ASP.NET中检查null或空文本和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!