开发者

if else statement for satisfying textbox insert not null and datatype varchar

Say I need to satisfy if else statement that

  1. CustomerCod开发者_JS百科e must be filled in(not null)
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜