Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.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/2/ruby-on-rails/57.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
如何从Access DB处理C#中的空值?_C#_Ms Access_Null - Fatal编程技术网

如何从Access DB处理C#中的空值?

如何从Access DB处理C#中的空值?,c#,ms-access,null,C#,Ms Access,Null,在我的C#表中,我有一个地址字段,我需要填写已经在Access数据库中分别存储了门号、街道、区域和位置的地址。我使用字符串连接来合并完整地址 object row = CBL_Customer_Name.Properties.GetDataSourceRowByKeyValue(CBL_Customer_Name.EditValue) as object; string getblocation = (row as DataRowView)["BLocation"].ToString(); s

在我的C#表中,我有一个地址字段,我需要填写已经在Access数据库中分别存储了门号、街道、区域和位置的地址。我使用字符串连接来合并完整地址

object row = CBL_Customer_Name.Properties.GetDataSourceRowByKeyValue(CBL_Customer_Name.EditValue) as object;

string getblocation = (row as DataRowView)["BLocation"].ToString();
string getbcity = (row as DataRowView)["BCity"].ToString();
string getbstate = (row as DataRowView)["BState"].ToString();
string getbcountry = (row as DataRowView)["BCountry"].ToString();

TXE_Invoice_Address.Text = (row as DataRowView)["BFlatNo"].ToString() + ", " + (row as DataRowView)["BPremises"].ToString() + "," + System.Environment.NewLine + (row as DataRowView)["BStreet"].ToString() + ", " + getloction(getblocation) + "," + System.Environment.NewLine + (row as DataRowView)["BArea"].ToString() + ", " + getcity(getbcity) + "," + System.Environment.NewLine + getstate(getbstate) + ", " + getcountry(getbcountry) + ".";
如果用户输入完整地址,则上述代码中没有问题。如果他没有输入位置或其他一些字段,那么我会在行尾得到
或空格。 如何解决这个问题?如果用户还留下1或2个字段,我需要在我的地址字段中有一个完美的地址。

使用
.replace()
将空值替换为自定义文本

示例

TXE\ U发票\地址.Text=TXE\ U发票\地址.Text.Replace(“,”,“,”))


此代码将删除所有可能导致奇怪地址格式的

尝试以下操作:
var newAddress=string.Join(“,”,TXE\u Invoice\u Address.Text.Split(“,”)。其中(x=>!string.IsNullOrWhiteSpace(x))

这将消除所有空格并重新连接到新字符串