Click here to Skip to main content
15,911,139 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 28-Sep-17 19:36pm

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
C#
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
}
 
Share this answer
 
string name=SqlCmd.Parameters["@ERESPTIME4"].Value;
If(string.IsNullOrEmpty(name)==ture)
{
// code when result is null or empty
}
else
{
// when not null or empty
}
 
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