c# - 从 C# 中的 SQL Server 中选择带有换行符 ("\n") 的记录
问题描述
我在 SQL Server 中有一条带有换行符(“\n”)的记录,我需要从 C# 中使用SqlCommand
. 这是我的 SQL 语句:
select customer_id, customer_name
from customer
where customer_id = 'Customer 1\n';
该记录存在于数据库中,但是当尝试使用 C# 检索它时,它不会被返回。我尝试了以下查询及其结果:
--Return the record
select customer_id, customer_name
from customer
where customer_id '%' + char(10) + '%'
--Not returning the record
select customer_id, customer_name
from customer
where customer_id char(10) + '%'
select customer_id, customer_name
from customer
where customer_id '%' + char(10)
任何帮助高度赞赏。
解决方案
DECLARE @NewLineChar AS CHAR(2) = CHAR(13) + CHAR(10)
select customer_id,customer_name from customer where customer_id='Customer' + @NewLineChar;
推荐阅读
- c# - C# Excel 在调试模式之外运行时不创建实例。(IIS 实例)
- sql - 如何将几个 SQL 查询合二为一?(微软 SQL)
- git - 切换分支后防止删除文件
- css - 为什么 flexbox 正确居中元素而定位属性却没有?
- python - 根据条件使用不同的上下文管理器
- tfs - TFS PBI/Bug 状态 - 当所有任务都设置为 Done 或 Removed 时
- javascript - ASP.NET Core 如何在发布中删除特定的 CSS 和 JavaScript 文件
- angular - 使用 angular-google-maps 动态添加语言/区域设置?
- audio - GStreamer - 从 MP4 文件生成音频波形
- linux - 从文件的特定行执行命令