Posts

Showing posts with the label WPF DataGrid

Donate

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

Image
Good day to all! Here's an example of a WPF CRUD (Create,Update and Delete) project using the DataGrid control, ADO.NET Entity Framework 6.x, C#.NET and Model–View–Viewmodel(MVVM) architectural pattern. This post was based from this tutorial WPF CRUD With DataGrid, Entity Framework And C#.NET except that we are now using the MVVM framework. The steps below are pretty straightforward and easy to follow. I. Project Setup 1. Add a table called Students in you database. The complete script is found in this post WPF CRUD With DataGrid, Entity Framework And C#.NET 2. Create a WPF Project and add four folders called DataAccess, Model, View and ViewModel. 3. Your project structure may look similar with the screenshot provided below. II. Coding The Model and Repository Class 1. Inside the Model folder, add an ADO.NET Entity Data Model that connects to the Students table in your database. On my part, I named it StudentModel . 2. For the connectionstring name in App.config file, I

WPF CRUD With DataGrid, RepoDB ORM And C#.NET

Image
Good day Gents, Here's a basic tutorial on how to integrate the RepoDB ORM into your WPF desktop application. I already have written an article in ASP.NET MVC web application here using the said ORM and I realized that I have to create an example for the desktop as well. To proceed working with the code, you need to run the create table script from this post WPF CRUD With DataGrid, Entity Framework And C#.NET . Next is to add a model class that maps the information from the database table to an object or list of objects. public class Students { public int ID { get ; set ; } public string Name { get ; set ; } public int Age { get ; set ; } public string Address { get ; set ; } public string Contact { get ; set ; } public Students() { ID = 0; Name = string .Empty; Age = 0; Address = string .Empty; Contact = string .Empty; } } Add an interface to the project that has the method signatures used in the actual repository class. The interface meth

WPF CRUD With DataGrid, Entity Framework And VB.NET

Image
Good morning! Here's the VB.NET version of this post WPF CRUD with DataGrid and Entity Framework C# . The steps to accomplish basing from the C# post are: a. Run the create table script assuming that you haven't created the Students table. b. Create a VB.NET WPF project. c. Replace the XAML markup of the window control. Once done, the scripts for the repository class and window code-behind are as follows: Repository Class Public Class StudentRepository Private studentContext As StudentEntities = Nothing Public Sub New () studentContext = New StudentEntities() End Sub Public Function GetStudent ( ByVal id As Integer ) As Student Return studentContext.Students.Find(id) End Function Public Function GetAll () As List( Of Student) Return studentContext.Students.ToList() End Function Public Sub AddStudent ( ByVal student As Student) If student IsNot Nothing Then

WPF CRUD With DataGrid, Entity Framework And C#.NET

Image
Good evening! Here's a simple WPF CRUD(Create/Update/Delete) application using DataGrid and Entity Framework. This doesn't involve the MVVM pattern and input validation. Maybe if I have time, in the future I'll post an MVVM equivalent post ( Update: I already have additional examples using RepoDB ORM and MVVM pattern in both C# and VB.NET at the end of this article ). So to proceed, execute the SQL script below and make sure to replace the database name with an existing one. USE [your_database] GO /****** Object: Table [dbo].[Students] Script Date: 3/31/2018 11:24:23 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Students]( [ID] [ int ] IDENTITY ( 1 , 1 ) NOT NULL , [Name] [ varchar ]( 50 ) NULL , [Age] [ int ] NULL , [Address] [ varchar ]( 50 ) NULL , [Contact] [ varchar ]( 50 ) NULL , CONSTRAINT [PK_Students] PRIMARY KEY CLUSTERED ( [ID] ASC ) WITH (PAD_INDEX = OFF , STATISTICS_N

Donate