2014-01-13 63 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]解決它,但它是可建議的嗎? –