<Window x:Class="WPF_Tutorial.Dataentry"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Dataentry" Height="443" Width="371"
Background="WhiteSmoke" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded">
<Grid Height="285" Width="286" x:Name="myGrid"
>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="99*"></ColumnDefinition>
<ColumnDefinition Width="187*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Margin="54,20,0,0">Rollno::</TextBlock>
<TextBlock Grid.Row="1" Margin="39,12,0,12">FirstName::</TextBlock>
<TextBlock Grid.Row="2" Margin="34,9,0,14">LastName::</TextBlock>
<TextBlock Grid.Row="3" Margin="22,10,185,12" Grid.ColumnSpan="2">CollegeName::</TextBlock>
<TextBlock Grid.Row="4" Margin="62,10,185,13" Grid.ColumnSpan="2">Mark::</TextBlock>
<TextBlock Grid.Row="5" Margin="33,10,3,17">ExamResult::</TextBlock>
<TextBox Grid.Column="1" Name="txtRollNo" Margin="0,7,40,10"
Text="{Binding Path=Rollno}"
></TextBox>
<TextBox Grid.Row="1" Grid.Column="1" Name="txtFirstName" Text="{Binding Path=FirstName}"
Margin="0,7,40,10" ></TextBox>
<TextBox Grid.Row="2" Grid.Column="1" Name="txtLastName" Margin="0,7,40,10"
Text="{Binding Path=Lastname}"
></TextBox>
<TextBox Grid.Row="3" Grid.Column="1" Name="txtClgname" Margin="0,7,40,10"
Text="{Binding Path=Colleagename}"
></TextBox>
<TextBox Grid.Row="4" Grid.Column="1" Name="txtMarks" Margin="0,7,40,10"
Text="{Binding Path=Marksobtaine}"
></TextBox>
<TextBox Grid.Row="5" Grid.Column="1" Name="txtexamresult" Margin="0,7,40,10"
Text="{Binding Path=Exam}"
></TextBox>
<Button Grid.Row="6" Name="btnAdd" Content="Insert" Margin="12,12,14,0" Click="btnAdd_Click"></Button>
<Button Grid.Row="6" Grid.Column="1" Name="btnLoad" Content="Load" Margin="13,12,102,0" Click="btnLoad_Click"></Button>
<Button Grid.Row="6" Grid.Column="1" Name="btnUpdate" Content="Update" Margin="91,12,12,0" Click="btnUpdate_Click"></Button>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Shapes;
using System.ComponentModel;
namespace
WPF_Tutorial
{
public partial class Dataentry : Window
{
Students objStudent = new Students(); //create object for student class
publicDataentry()
{
InitializeComponent();
}
//insert record
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
try
{
objStudent.Insetrt();
MessageBox.Show("Record inserted", "Insert");
//clearField
txtRollNo.Text = "";
txtFirstName.Text = "";
txtLastName.Text = "";
txtClgname.Text = "";
txtexamresult.Text = "";
txtMarks.Text = "";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//load record
private void btnLoad_Click(objectsender, RoutedEventArgs e)
{
if(txtRollNo.Text != null)
{
try
{
objStudent.Load();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show("enter correct code");
}
}
//updaterecord
private void btnUpdate_Click(objectsender, RoutedEventArgs e)
{
if(txtRollNo.Text != null)
{
try
{
objStudent.update();
MessageBox.Show("Update Record", "Update");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void Window_Loaded(objectsender, RoutedEventArgs e)
{
myGrid.DataContext = objStudent;
}
}
}
This article is meant for beginners.