Introduction
This article explains how to work with Windows Forms applications in F# and how to import the namespaces. In addition you will see how to connect with a SQL Server database from the Windows Forms application and how to add user controls in the Windows Forms application. I have shown how to import the essential namespaces in F#.
At first to create the database in SQL Server, write the following code in database SQL Server.
create database UserInformation
use UserInformation
create table EmployeeInfo(
EmpId int,
FirstName varchar(30),
LastName varchar(30),
Salary money,
Address nvarchar(max),
City varchar(30)
)
Now use the following steps in Visual Studio 2012.
Step 1:
Open Visual Studio 2012 and select "New project" --> "Visual F#" -> "F# console application" to create your F# application.
Step 2:
In this step you need to go at solution explorer and right-click on references and select the add references see the figure given below

Step 3:
After selecting "Add References", in the framwork template you need to select System.Windows.Forms, System.Drawing and System.Data while holding down the Ctrl key and Click on "Ok."

Step 4:
Write the following code in the F# console application.
//Importing Namespace
open System
open System.Windows.Forms
open System.Drawing
open System.Data.SqlClient
open System.Data
// Creating Form & User Controls
// Form
let MyForm = new Form(Height =400, Width = 500)
// Labels
let lbl1 = new Label(Top =20 , Height =30, Width = 50)
let lbl2 = new Label(Top =50 , Height =30, Width = 100)
let lbl3 = new Label(Top =80 , Height =30, Width = 100)
let lbl4 = new Label(Top =110 , Height =30, Width = 50)
let lbl5 = new Label(Top =140 , Height =30, Width = 50)
let lbl6 = new Label(Top =170, Height =30, Width = 50)
// TextBoxes
let txt1 = new TextBox(Top =20, Left =120)
let txt2 = new TextBox(Top =50, Left =120)
let txt3 = new TextBox(Top =80, Left =120)
let txt4 = new TextBox(Top =110,Left=120)
let txt5 = new TextBox(Top =140,Left=120)



Bhuvanesh MohankumarPosted Apr 30, 2016, 3:16 PM
Good one...