Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Loengwpf DB

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

T

andmebaasiga
Andmebaasi henduse loomine
Server Explorer aknas vali Data Connec1onAdd Connec1on
(vali acsessi andmebaas) ja ilmub andmebaasi struktuur
App.con6ig
Tida fail app.cong automaatselt andmebaasi hendamiseks

<connec?onStrings>
<add name="DefaultConnec?on"
connec?onString="Provider=MicrosoH.Jet.OLEDB.4.0;Data Source=|
DataDirectory|\world.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />
</connec?onStrings>
Lisa kasutajaliides
<Window x:Class="Wpf_db.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Wpf_db"
mc:Ignorable="d"
Title="MainWindow" Height="250" Width="350" Loaded="Window_Loaded">
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="20 8 20 8" />
<Setter Property="Width" Value="100" />
<Setter Property="Height" Value="30" />
</Style>
</Window.Resources>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid AutoGenerateColumns="False" x:Name=countriesGrid">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Code}" Header="Code" Width="120"/>
<DataGridTextColumn Binding="{Binding Name}" Header="Name" Width="125"/>
<DataGridTextColumn Binding="{Binding Continent}" Header="Continent" Width="80"/>
</DataGrid.Columns>
</DataGrid>

<StackPanel HorizontalAlignment="Center" Grid.Row="1" Orientation="Horizontal">
<Button x:Name="updateButton" Content="Uenda" Click="updateButton_Click" />
<Button x:Name="deleteButton" Content="Kustuta" Click="deleteButton_Click" />
</StackPanel>
</Grid>

</Window>
Dll lisamine
Kui te sovite kasutada app.cong andmed, on vaja lisada System.Congura1on.dll


connec1onString =
Congura1onManager.Connec1onStrings["DefaultConnec1on"].Connec1onString;
Grid objekti titmine
Andmete uuendamine
Grid rea lisamine
ENTITY FRAMEWORK
Entity Framework kasutamine
ORM tehnoloogia, annab vimalust ttada andmetega
objek? abil
Loo SQL Server Database fail
countrydb
CREATE TABLE [dbo].[Country] (
[Code] NVARCHAR (5) NOT NULL,
[Name] NVARCHAR (200) NULL,
[Con?nent] NVARCHAR (200) NULL,
[Region] NVARCHAR (200) NULL,
[SurfaceArea] FLOAT,
[InderYear] INT ,
[Popula?on] INT ,
[GovernmentForm] NVARCHAR (200) NULL,
[HeadOfState] NVARCHAR (200) NULL,
[Capital] NVARCHAR (5),
CONSTRAINT [PK_dbo.Country] PRIMARY
KEY CLUSTERED ([Code] ASC)
);

Entity Data Model
Loo mudel andmebaasi alusel. Automaatselt ilmuvad klassid,
mis vastavad tabeli sisule ja Model.Context klass raamis?ku
hendamiseks
App. Con6ig tidetakse
automaatselt
Vaata App.cong
Model andmed
Klassid, mis vastavad andmebaasi tabeli struktuurile


Context klass annab vimalust ttada En?ty Frameworkiga
Vormi Xaml
Tidame grid
Programmerime nupud
Programmeerime nupud (2)

You might also like