使用 C#、WPF、.NET 4.5 在我的程序中,我试图从数据库中填充 TextBox 的值。该值是通过 LINQ 语句获得的。我已经尝试了所有不同的东西,比如To.String()
等等Console.WriteLine()
。如果你能找到一种很棒的方法来完成这项工作,如果你能找到一种更好的方法来选择数据并显示它,我会对此感兴趣出色地。C#代码:
private AuroraEntities auroraContext = null;
private void LoadTB()
{
this.auroraContext = new AuroraEntities();
ObjectQuery<Inventory> inventories = auroraContext.Inventories;
string name = ingNameCB.SelectedValue.ToString();
var queryResult = (from q in inventories
where q.InventoryName == name
select q);
textBox1.DataContext = queryResult.ToString();
}
XAML:
<TextBox Height="23" HorizontalAlignment="Left" Margin="70,186,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Text="{Binding Path=InventoryName, Mode=TwoWay}"
谢谢!