if else statement for satisfying textbox insert not null and datatype varchar
Say I need to satisfy if else statement that
- CustomerCod开发者_JS百科e must be filled in(not null)
- CustomerCode must be dataType varchar
How to write if else correctly? Thanks for any help in advanced, guys!
sqlCustomerMaster.InsertParameters["CustomerCode"].DefaultValue =
txtCustomerCode.Text.ToString();
try
{
txtCustomerCode.Text = "";
if (txtCustomerCode.Text != null)
{
sqlCustomerMaster.Insert();
}
else
{
}
}
Since the input is from a text box there always should be a mapping to varchar
, so you just want to check whether the string is null or empty:
if (!string.IsNullOrEmpty(txtCustomerCode.Text))
{
sqlCustomerMaster.Insert();
}
This will guarantee txtCustomerCode.Text
has at least one character but not whether its numeric etc, but you did not list any other conditions.
精彩评论