开发者

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

开发者 https://www.devze.com 2023-03-12 20:14 出处:网络
Say I need to satisfy if else statement that CustomerCod开发者_JS百科e must be filled in(not null)

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

精彩评论

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