Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LINQ文本框与数据库匹配_C#_Asp.net_Linq To Sql - Fatal编程技术网

C# LINQ文本框与数据库匹配

C# LINQ文本框与数据库匹配,c#,asp.net,linq-to-sql,C#,Asp.net,Linq To Sql,我试图在LINQ update语句中运行以下命令 if (updateProfile.website == txtSite.Text) { } else { updateProfile.website = txtSite.Text; } 这只是检查文本框值是否与数据库中的值匹配,如果匹配,则继续,如果不匹配,则更新 我遇到的问题是,如果文本框为空,则它将传入“”,因此为空值。如果文本框为“”,我希望它继续,这样它会在DB中保留空值 非常感谢您提供的所有帮助。您可能需要使用wantstring.

我试图在LINQ update语句中运行以下命令

if (updateProfile.website == txtSite.Text) { }
else { updateProfile.website = txtSite.Text; }
这只是检查文本框值是否与数据库中的值匹配,如果匹配,则继续,如果不匹配,则更新

我遇到的问题是,如果文本框为空,则它将传入“”,因此为空值。如果文本框为“”,我希望它继续,这样它会在DB中保留空值


非常感谢您提供的所有帮助。

您可能需要使用want
string.IsNullOrEmpty()
,它基本上实现了以下功能:

if(string.IsNullOrEmpty(txtSite.Text) || updateProfile.website == txtSite.Text) { }
else { updateProfile.website = txtSite.Text; }
或者,如果您只关心值
,并且希望将其与
null
区别对待,则可以明确检查:

if (txtSite.Txt == "" || updateProfile.website == txtSite.Text) { }
else { updateProfile.website = txtSite.Text; }

或者您可以像这样选中文本框,然后添加条件

if (txtSite.Text.Trim().Length > 0)
{
    if (updateProfile.website == txtSite.Text) { }
    else { updateProfile.website = txtSite.Text; }
}

非常感谢,工作很愉快我刚刚使用了第一个建议:)