views:

74

answers:

0

Here's a part of XAML of the application I'm working on:

<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>

And the corresponding 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

Is this code correct to fill this table? If not, why? Honestly, I've found several perspectives on how to do this sort of thing, some of which are linked below:

From switchonthecode
From csharpcorner
From Allen Mack's blog