以最简单的方式以WPF Datagrid显示查询结果 [英] Display query results in WPF Datagrid simplest way

查看:65
本文介绍了以最简单的方式以WPF Datagrid显示查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我尝试了以下代码,但无法在WPF数据网格上查询查询结果.

hi i tried the below code but not working to diaply query results on WPF data grid., any inpus pls.

using (SqlConnection sqlConn = new SqlConnection())
{
    sqlConn.ConnectionString = connectionString;
    string queryString = "select * from dob.table_1";
    sqlConn.Open();

    DataTable table = new DataTable();
    SqlDataAdapter a = new SqlDataAdapter(queryString, sqlConn);
    a.Fill(table);

    this.datagird1.DataContext = table;
}

Datagrid XAML:

Datagrid XAML:

<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False" Grid.Row="1"
Height="219" HorizontalAlignment="Left" Name="datagird1" VerticalAlignment="Top"
Width="499" AllowDrop="True" />

推荐答案

这已经晚了3年,但对其他通过google到达这里的人来说却很好.请看一下这个例子,这正是您所需要的: http://www.codeproject.com/Tips/362436/Data-binding-in-WPF-DataGrid-control

This is 3 years too late, but good for other people that arrive here via google. Please have a look at this example, this is exactly what you need: http://www.codeproject.com/Tips/362436/Data-binding-in-WPF-DataGrid-control

这篇关于以最简单的方式以WPF Datagrid显示查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆