【发布时间】:2018-04-14 01:47:11
【问题描述】:
我正在尝试将文件扩展名连接到字符串,但它不起作用。我有一本这样的字典:
Dictionary<string, List<string>> myDict = new Dictionary<string, List<string>>();
从 SQL Server 存储过程的结果中填充键:
List<string> myList = new List<string>();
using (SqlConnection conn = GetConnection())
{
conn.Open();
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "Execute getTitles @Title";
comm.Parameters.Add("@Title", SqlDbType.VarChar).Value = title;
using (var reader = comm.ExecuteReader())
{
while (reader.Read())
{
myList.Add(reader["Title"].ToString());
}
}
conn.Close();
}
这个列表被加载到字典键中,但我不会进入值,因为它不应该是相关的,你可能不想阅读几十行代码。
一旦我准备好使用这些数据,我就会这样做:
string fileName = title + ".jpg";
但是当我调试时:
Debug.WriteLine("fileName: " + fileName);
它只写标题值(没有“.jpg”)。这可能是什么?
【问题讨论】:
-
您的代码示例中不包含问题。您可能需要稍微隔离一下并发布相关代码。没有办法回答这个问题,因为它是目前写的。
-
可能标题包含换行符?
-
尝试将其归结为minimal reproducible example。我怀疑这样做会让您自己找到它;但如果没有,其他人届时将能够提供帮助。就目前的问题而言,当然还不够。您提供的 Sql 将与问题无关(但您应该将 SqlCommand 放在
using块中)。
标签: c# sql asp.net-core