C# 如何在获取数据时删除特殊字符
下面是我获取数据的查询,我的问题是,我将地址字段存储为C# 如何在获取数据时删除特殊字符,c#,winforms,ms-access,C#,Winforms,Ms Access,下面是我获取数据的查询,我的问题是,我将地址字段存储为 Address1%Address2%Address3 现在,在获取时,我想将其作为地址1(换行)地址2(换行)地址3 我怎么能做到 例如Dange%abc%Pune 危险 abc 浦那 我会改变你存储数据的方式。你可以介绍一个新的表,医生-主人-地址。如果每个医生只有一个地址,您还可以向Doctor_Master添加更多列。这样你就知道肯定会有一个街道名称、省名、邮政编码、国家等 如果仍然选择使用值字段,则可以将地址作为xml存储在该字段中
Address1%Address2%Address3
现在,在获取时,我想将其作为地址1(换行)地址2(换行)地址3
我怎么能做到
例如Dange%abc%Pune
危险
abc
浦那
我会改变你存储数据的方式。你可以介绍一个新的表,医生-主人-地址。如果每个医生只有一个地址,您还可以向Doctor_Master添加更多列。这样你就知道肯定会有一个街道名称、省名、邮政编码、国家等 如果仍然选择使用值字段,则可以将地址作为xml存储在该字段中,以便轻松序列化数据。如果省略了Address2,然后解析了Address1%Address3怎么办?如果它只是由“%”分隔,您如何知道Address3代表什么
如果您仍然选择使用一个以%分隔的字段,请签出拆分字符串信息。我将更改您存储数据的方式。你可以介绍一个新的表,医生-主人-地址。如果每个医生只有一个地址,您还可以向Doctor_Master添加更多列。这样你就知道肯定会有一个街道名称、省名、邮政编码、国家等 如果仍然选择使用值字段,则可以将地址作为xml存储在该字段中,以便轻松序列化数据。如果省略了Address2,然后解析了Address1%Address3怎么办?如果它只是由“%”分隔,您如何知道Address3代表什么
如果您仍然选择使用一个以%分隔的字段,请签出拆分字符串信息。我将更改您存储数据的方式。你可以介绍一个新的表,医生-主人-地址。如果每个医生只有一个地址,您还可以向Doctor_Master添加更多列。这样你就知道肯定会有一个街道名称、省名、邮政编码、国家等 如果仍然选择使用值字段,则可以将地址作为xml存储在该字段中,以便轻松序列化数据。如果省略了Address2,然后解析了Address1%Address3怎么办?如果它只是由“%”分隔,您如何知道Address3代表什么
如果您仍然选择使用一个以%分隔的字段,请签出拆分字符串信息。我将更改您存储数据的方式。你可以介绍一个新的表,医生-主人-地址。如果每个医生只有一个地址,您还可以向Doctor_Master添加更多列。这样你就知道肯定会有一个街道名称、省名、邮政编码、国家等 如果仍然选择使用值字段,则可以将地址作为xml存储在该字段中,以便轻松序列化数据。如果省略了Address2,然后解析了Address1%Address3怎么办?如果它只是由“%”分隔,您如何知道Address3代表什么
如果您仍然选择使用一个以%分隔的字段,请签出拆分字符串信息。很遗憾,
Microsoft.Jet.OLEDB.4.0
提供程序不支持Replace()
函数,就像Microsoft.ACE.OLEDB.12.0
提供程序那样,否则对您来说就容易多了
我认为您必须正常获取地址
字段,并使用助手函数将该字符串
转换为您想要的格式,如下所示:
public string GetBrokenLines(string address){
return address.Replace("%","\r\n");
}
//instead of using the address directly, you just need to pass it into the GetBrokenLines
//method and get the expected result.
要使用适配器填充数据表,请尝试以下操作:
public static DataTable GetRefDrList(string typeofDr, bool display){
DataTable refDrListTable = new DataTable();
refDrListTable.RowChanged += Format;
//....
da.Fill(refDrListTable);
//....
}
bool suppressFormat;
private void Format(object sender, DataRowChangedEventArgs e){
if(suppressFormat) return;
suppressFormat = true;
e.Row["Address"] = e.Row["Address"].ToString().Replace("%","\r\n");
suppressFormat = false;
}
遗憾的是,
Microsoft.Jet.OLEDB.4.0
提供程序不像Microsoft.ACE.OLEDB.12.0
提供程序那样支持Replace()
我认为您必须正常获取地址
字段,并使用助手函数将该字符串
转换为您想要的格式,如下所示:
public string GetBrokenLines(string address){
return address.Replace("%","\r\n");
}
//instead of using the address directly, you just need to pass it into the GetBrokenLines
//method and get the expected result.
要使用适配器填充数据表,请尝试以下操作:
public static DataTable GetRefDrList(string typeofDr, bool display){
DataTable refDrListTable = new DataTable();
refDrListTable.RowChanged += Format;
//....
da.Fill(refDrListTable);
//....
}
bool suppressFormat;
private void Format(object sender, DataRowChangedEventArgs e){
if(suppressFormat) return;
suppressFormat = true;
e.Row["Address"] = e.Row["Address"].ToString().Replace("%","\r\n");
suppressFormat = false;
}
遗憾的是,Microsoft.Jet.OLEDB.4.0
提供程序不像Microsoft.ACE.OLEDB.12.0
提供程序那样支持Replace()
我认为您必须正常获取地址
字段,并使用助手函数将该字符串
转换为您想要的格式,如下所示:
public string GetBrokenLines(string address){
return address.Replace("%","\r\n");
}
//instead of using the address directly, you just need to pass it into the GetBrokenLines
//method and get the expected result.
要使用适配器填充数据表,请尝试以下操作:
public static DataTable GetRefDrList(string typeofDr, bool display){
DataTable refDrListTable = new DataTable();
refDrListTable.RowChanged += Format;
//....
da.Fill(refDrListTable);
//....
}
bool suppressFormat;
private void Format(object sender, DataRowChangedEventArgs e){
if(suppressFormat) return;
suppressFormat = true;
e.Row["Address"] = e.Row["Address"].ToString().Replace("%","\r\n");
suppressFormat = false;
}
遗憾的是,Microsoft.Jet.OLEDB.4.0
提供程序不像Microsoft.ACE.OLEDB.12.0
提供程序那样支持Replace()
我认为您必须正常获取地址
字段,并使用助手函数将该字符串
转换为您想要的格式,如下所示:
public string GetBrokenLines(string address){
return address.Replace("%","\r\n");
}
//instead of using the address directly, you just need to pass it into the GetBrokenLines
//method and get the expected result.
要使用适配器填充数据表,请尝试以下操作:
public static DataTable GetRefDrList(string typeofDr, bool display){
DataTable refDrListTable = new DataTable();
refDrListTable.RowChanged += Format;
//....
da.Fill(refDrListTable);
//....
}
bool suppressFormat;
private void Format(object sender, DataRowChangedEventArgs e){
if(suppressFormat) return;
suppressFormat = true;
e.Row["Address"] = e.Row["Address"].ToString().Replace("%","\r\n");
suppressFormat = false;
}
首先,这段代码容易受到SQL注入的攻击。您将希望使用参数化查询,而不是将值直接连接到SQL代码中。除此之外,还不清楚你的问题是什么。但听起来好像您没有正确存储数据。多个值不应该放在一个字段中,它们应该被分解成多个字段或多个记录。我不明白。请澄清您的问题。@SonerGönül在“地址”列中,我将3个文本框值存储在一起,并使用%
字符对它们进行操作,现在在提取时,我希望这3个值在报告中以3行不同的形式显示出来,所以对于初学者,我如何做到这一点,这段代码容易受到SQL注入的攻击。您将希望使用参数化查询,而不是将值直接连接到SQL代码中。除此之外,还不清楚你的问题是什么。但听起来好像您没有正确存储数据。多个值不应该出现在一个字段中,它们应该被分解成多个f