Hi everyone I work with Visual Studio 2010 and C# programming language. I have a problem reading data from the oracle database. I created a WPF application with my main Window Xaml and class files and 1 more class called DataFiles. The thing I want is to read some data from the database on my grid in my WPF window. Problem is even though it connects to the database the grid is always empty. It isn't the connection string as I tested it and it connects to the database the problem seems to be in showing the LASTNAME (PREZIME in my native tongue) on the grid which is what it's supposed to do.
Here is the code:
Data Files Code
\
using System;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace SQLKonekcija
{
public class clsEmployee
{
public string Prezime { get; set; }
}
public class DataAccess
{
OleDbConnection oleCon;
OleDbCommand oleComd;
public DataAccess()
{
string connectionString = "provider=ORAOLEDB.ORACLE; data source=ORCL; password=****; user id=****;";
oleCon = new OleDbConnection(connectionString);
}
public ObservableCollection<clsEmployee> GetAllEmployee()
{
ObservableCollection<clsEmployee> EmpCol = new ObservableCollection<clsEmployee>();
oleComd = new OleDbCommand();
oleComd.Connection = oleCon;
oleComd.CommandText = "Select PREZIME from UPOSLENICI";
oleCon.Open();
OleDbDataReader Reader = oleComd.ExecuteReader();
Reader.Read();
while (Reader.Read())
{
EmpCol.Add(new clsEmployee()
{
Prezime = Reader["PREZIME"].ToString()
});
}
oleCon.Close();
return EmpCol;
}
And here is my main window.cs code
public partial class MainWindow : Window
{
clsEmployee objEmpToAdd;
DataAccess objDs;
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
objDs = new DataAccess();
dgEmp.ItemsSource = objDs.GetAllEmployee();
And the XAML
<Window x:Class="SQLKonekcija.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
<DataGrid AutoGenerateColumns="False" Height="237"
HorizontalAlignment="Left" Margin="18,66,0,0" Name="dgEmp"
VerticalAlignment="Top" Width="466" ColumnWidth="*"
>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding PREZIME}" Header="Prezime"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
<TextBlock Height="42" HorizontalAlignment="Left" Margin="18,15,0,0" Name="textBlock1" Text="TEST CONNECTION" VerticalAlignment="Top" Width="462" TextAlignment="Center" FontSize="28" FontWeight="ExtraBold" />
</Grid>
</Window>
The guys on the MSDN forums told me I should ask the question here so sorry if it's not your field.
Hope u guys can help, thanks.