1
我正在从Windows窗体移动到WPF,但现在我有一个问题。wpf:如何在网格视图中显示数据集?
我从数据库(SQL Server)的信息,并存储在数据集中,我想表明,在一个DataGrid(DG)
DataSet ds = new DataSet();
SqlConnection sc = new SqlConnection("mysqlconnection");
SqlDataAdapter sd = new SqlDataAdapter();
sc.Open();
sd.SelectCommand = new SqlCommand("SELECT * FROM table_1", sc);
sd.Fill(ds);
dg.DataContext = ds.Tables[0].DefaultView;//here is the problem
sc.Close();
在Windows窗体是dg.DataSrouce
,但我无法找到在wpf中,有什么帮助?
感谢您的回答,我可以看到有4行是真的,但我没有看到这4行内的任何列或数据! – trrrrrrm 2011-03-04 07:42:08
@ From.ME.to.YOU:更新了我的答案,尝试在'DataGrid'定义中设置'AutoGenerateColumns ='True'' – 2011-03-04 07:43:55
非常感谢,像魔术一样工作! – trrrrrrm 2011-03-04 07:48:14