How to Connect to and Modify a SQL Server Database with C# (WPF/LINQ) @crclayton
How to Connect to and Modify a SQL Server Database with C# (WPF/LINQ)  @crclayton
Uploaded September 2015 | Updated September 2026, 3 hours ago
In this video I show how to connect to and modify a SQL Server Database table through a WPF C# application.

I use SQL Server Express 2014 and Visual Studio Community Edition 2015 here, but I've used other versions in the past and its been the same.

C# Code:

using System.Windows;
namespace ExampleApplication
{
public partial class MainWindow : Window
{
ExampleLINQtoSQLClassDataContext dc = new ExampleLINQtoSQLClassDataContext(
Properties.Settings.Default.ExampleDatabaseConnectionString);

public MainWindow()
{
InitializeComponent();

if (dc.DatabaseExists()) ExampleDatagrid.ItemsSource = dc.NewTables;
}

private void SaveButton_Click(object sender, RoutedEventArgs e)
{
dc.SubmitChanges();
}
}
}

The XAML Code (replace the braces with angle-brackets, YouTube doesn't allow the angle brackets in the description):

{Window x:Class="ExampleApplication.MainWindow"
xmlns="schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="schemas.microsoft.com/expression/blend/2008"
xmlns:mc="schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ExampleApplication"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525"}
{Grid}
{DataGrid Name="ExampleDatagrid" Margin="0,0,0,33" }{/DataGrid}
{Button Name="SaveButton" Click="SaveButton_Click" Content="Save" Margin="0,286,0,0"}{/Button}
{/Grid}
{/Window}
How to Connect to and Modify a SQL Server Database with C# (WPF/LINQ)How to Instantaneously Geolocate People on Omegle (Wireshark/Python)Is Automation Ethical?How to Make 2D/3D Graphs on an HP-50GDeaths by Natural DisasterHow to Convert Units with the HP-50gHow to Set Up a Local HTTP Server (Node.js)How to Contribute to Someones GitHub Repository (Fork/Pull Request)
Charles Clayton |

How to Connect to and Modify a SQL Server Database with C# (WPF/LINQ)

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER