c# - 获取列表中对象的属性值
问题描述
我想从列表中的对象获取属性值并将其放入 textbox.text
下面我有一个我的代码示例:
物体:
public class Incident
{
public int Incident_id { get; set; }
public string Description { get; set; }
public string Caller { get; set; }
}
以下是我的表单类中的代码:
List<Incident> incidentById = new List<Incident>();
incidentById = db.GetIncidentById(ID);
当我的列表被填满时,我想将字符串 Caller 放入一个文本框中,如下所示:
textBoxCaller.Text = incidentById[1].Caller;
我被困在这一点上,所以我希望有人可以帮助我。谢谢!
编辑:
public List<Incident> GetIncidentById(int id)
{
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("IncidentLog")))
{
var output = connection.Query<Incident> ($"select * from Incidents where Incident_id like @id", new { id = "%id%" }).ToList();
return output;
}
}
解决方案
我没有将正确的值传递给我的查询,这成功了!你想要的是$"select * from Incidents where Incident_id = @id", new { id }
推荐阅读
- c++ - 停止 C++ 中的特定线程
- excel - 使用条件偏移工作表中的单元格
- python - Scrapy - 如何使用 AWS Lambda 函数运行蜘蛛?
- angular6 - 用于 tr 元素的 Angular 6 / TSLint 组件选择器
- sublimetext3 - 如何修复这个 Sublime SFTP 解析错误?
- c# - “System.Net.Http”中都存在“MediaTypeHeaderValue”类型
- python - contourf() 在有限数据上绘制空白
- node.js - 如何使用 ffi 处理引用?
- sql - 创建视图错误列名必须是唯一的
- ubuntu - 使用提示自动化 apt-get install dnsmasq