This shows how to develop a desktop application using LINQ To SQL Class.
I am using Visual Studio 2010 and SQL Server 2005. So let's start.
1. First of all open your Visual Studio and go for a new project.
![open visual studio]()
2. Then click on the Windows project.
![windows project]()
3. Now right-click on the project and select add new item.
![add new item]()
4. And select a LINQ To SQL class file and click on add.
![Linq To SQL class file]()
5. When you will click o the add button a dbml file will added to your project.
![dbml file]()
![Class]()
6. Now you need to drag and drop the table from the Server Explorer to the dbml file.
![server explorer to dbml file]()
When you drag and drop the first table to the dbml file, connection string will be saved in the app.config file automatically.
![Connection String]()
7. Now design the login form.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Project_HMS
{
public partial class Form1 : Form
{
//Object of dbml file..
HMS_DataBase_LinkDataContext linq = new HMS_DataBase_LinkDataContext();
//Object of user table
HMS_User_Master obj_user = new HMS_User_Master();
public Form1()
{
InitializeComponent();
}
}
private void btn_login_Click(object sender, EventArgs e)
{
int a = chk_user();
if (a == 1)
{
MDIParent1 obj_mdi = new MDIParent1();
obj_mdi.Show();
}
else
{
MessageBox.Show("User Name Or Password Is Wrong Please Try Again");
txt_name.Text = string.Empty;
txt_pass.Text = string.Empty;
}
}
public int chk_user()
{
var chk_user = from user in linq.HMS_User_Masters
where user.user_name == txt_name.Text && user.password == txt_pass.Text
&& user.Isdelete==0
select user;
if (chk_user.Count() > 0)
{
return 1;
}
else
{
return 0;
}
}
![login form]()
![Output]()
I will continue in my next article.