2012-03-15 86 views
0

我已經嘗試過Google搜索,所以我放棄了試圖尋找。在datagrid中顯示數據集?

我想在wpf數據網格中顯示數據集。之後,我將需要在文本框中顯示單個列值。然後,我可以更改這些文本框中的值並按下提交按鈕等提交對數據庫的更改。這是我迄今爲止的代碼。

` 昏暗CON作爲新的SqlConnection 昏暗dbConnString作爲字符串 昏暗的DS作爲新的數據集 昏暗達作爲新的SqlDataAdapter 昏暗的SQLStatement作爲字符串

dbConnString = "Data Source=SG2;Initial Catalog=RovisysAsiaITAssets;User ID=sa;Password=Rovisys2012" 
    con.ConnectionString = dbConnString 
    con.Open() 

    sqlStatement = "SELECT * FROM TabletInventory" 
    da = New SqlDataAdapter(sqlStatement, con) 
    da.Fill(ds, "TabletInventory") 

`

任何人可以幫助我嗎?即使是讀一個指針也沒問題。謝謝!

+0

代碼嘗試閱讀本:http://www.codeproject.com/Articles/30905/WPF-DataGrid-Practical-Examples – emybob 2012-03-15 10:47:47

回答

0
Your xaml code should look like something like this. 

<DataGrid Name="DataGrid1" 
    ItemsSource="{Binding Path=TabletInventory}" 
    AutoGenerateColumns="True" /> 

背後

dbConnString = "Data Source=SG2;Initial Catalog=RovisysAsiaITAssets;User ID=sa;Password=Rovisys2012" 
    con.ConnectionString = dbConnString 
    con.Open() 
    sqlStatement = "SELECT * FROM TabletInventory" 
    da = New SqlDataAdapter(sqlStatement, con) 
    da.Fill(ds, "TabletInventory") 
    DataGrid1.DataContext = ds;