0
這裏是XAML的應用我工作的一部分:WPF綁定一個ListView到Oracle數據源
<ListView Name="lsvCustomerDetails" ItemsSource="{Binding myDataTable}">
<ListView.View>
<GridView>
<GridViewColumn Header="Script Name" DisplayMemberBinding="{Binding ID}"/>
<GridViewColumn Header="Status" DisplayMemberBinding="{Binding status}"/>
<GridViewColumn Header="Date" DisplayMemberBinding="{Binding date}"/>
</GridView>
</ListView.View>
</ListView>
和相應的VB.NET:
Class Window1
Public myDataTable As DataTable
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim objOracleConnection As New OracleConnection("Data Source=DB;User Id=user;Password=password;")
Dim objOracleCommand As New OracleCommand
Dim objOracleReader As OracleDataReader
objOracleConnection.Open()
objOracleCommand.Connection = objOracleConnection
objOracleCommand.CommandText = "SELECT * FROM customers"
objOracleReader = objOracleCommand.ExecuteReader()
Using objOracleConnection
Dim objOracleAdapter As OracleDataAdapter = New OracleDataAdapter(objOracleCommand.CommandText, objOracleConnection)
objOracleAdapter.Fill(myDataTable)
End Using
lsvCustomerDetails.DataContext = myDataTable
objOracleConnection.Close()
End If
End Using
這是正確的代碼填補這張桌子?如果不是,爲什麼?如何做到這樣的事情老實說,我發現了幾個觀點,其中一些鏈接如下:
From switchonthecode
From csharpcorner
From Allen Mack's blog
這確實比我所擁有的更清潔和更好。我會研究它。 – Riddari 2011-07-11 19:47:58