[英]Select a specific column in SQL Server from a concatenation from a different table
[英]Select Specific Column from a Linked Server Table
我有以下 C# 代碼可以從鏈接服務器上的表中選擇一列:
var query2 = $@"select [FileName] from [AMS_H2H].[H2H].[dbo].[FileReconciliation] where ProductCode = @productCode";
LayZConnection(); //make the db connection
var candidates = _dbConnection.Query<int>(query2, new { productCode = "ACHDH" });
運行它時,我收到以下錯誤:
"Input string was not in a correct format."
如果我的查詢如下所示,我選擇所有列,則它有效:
var query2 = $@"select * from [AMS_H2H].[H2H].[dbo].[FileReconciliation]
僅選擇 FileName 的正確格式是什么。 順便說一句,第一個查詢從 MSSMS 工作正常。
您在Query<int>
指定了一種int
類型,這將導致 Dapper 嘗試將查詢結果映射到一個整數,但是您的查詢在select [FileName]
返回一個文件名,這表明它是一個字符串。
更改類型Query<string>
應該可以解決問題。
Dapper 的文檔中提供了有關 Dapper 的 Query 方法的更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.