2014-01-13 65 views
1

我想在.Net F/W 4.0上使用C#构建一个非常简单的WPF应用程序。当我点击一个按钮时,我希望它对Oracle数据库运行一个sql查询(存储在“finalupdatedsql1”变量中)。 我想要Datagrid上的结果。出于某种原因Datagrid.DataSource属性无法识别。任何人都可以用另一种方法来帮助我,或纠正我的代码吗?仅供参考,我正在使用ODP.Net和Oracle连接测试。谢谢。C#WPF DataSource属性无法识别

private void RunSQL_Click(object sender, RoutedEventArgs e) 
    { 
     cmd = new OracleCommand(finalupdatedsql1, conn);//finalupdatedsql1 has the sqlquery in string representation. 
     cmd.CommandType = CommandType.Text; 
     da = new OracleDataAdapter(cmd); 
     cb = new OracleCommandBuilder(da); 
     ds = new DataSet(); 
     da.Fill(ds); 
     MyDataGrid.DataSource = ds.Tables[0];//DataSource not showing up in intellisense or recognizing 


     conn.Close(); 
     conn.Dispose(); 
    } 
+0

'MyDataGrid.DataSource'用于winforms'DatagridView'代码 – Jim

回答

1

您正在寻找ItemsSource

MyDataGrid.ItemsSource = ds.Tables[0]; 

DataSource属性将是一个Windows Forms应用。

+0

ds.Tables [0]给出错误。将其更改为(System.Collections.IEnumerable)ds.Tables [0]解决它,但它是可建议的吗? –