Reputation: 2528
I am trying to run the following in a LINQ update statement.
if (updateProfile.website == txtSite.Text) { }
else { updateProfile.website = txtSite.Text; }
This simply checkes to see if the textbox value matches the one in the DB, if it does then it moves on, if not it updates it.
The problem i have is that if the textbox is empty its passing in "" so a blank value. I would like it to move on if the textbox is "", this way it leaves the null value in the DB.
All help is much appreciated, thanks.
Upvotes: 0
Views: 218
Reputation: 1424
or you can check your textbox like this and then add your conditions
if (txtSite.Text.Trim().Length > 0)
{
if (updateProfile.website == txtSite.Text) { }
else { updateProfile.website = txtSite.Text; }
}
Upvotes: 1
Reputation: 9588
You'll probably want to use want string.IsNullOrEmpty()
, which pretty much does what it says:
if(string.IsNullOrEmpty(txtSite.Text) || updateProfile.website == txtSite.Text) { }
else { updateProfile.website = txtSite.Text; }
Alternatively, if you only care about the value ""
and want to treat it distinctly from null
, you can just check for that explicitly:
if (txtSite.Txt == "" || updateProfile.website == txtSite.Text) { }
else { updateProfile.website = txtSite.Text; }
Upvotes: 1