open System
open System.Windows.Forms
open System.Data
open System.Data.SqlClient
open System.Drawing
let duplrecform=new Form(Text="Remove Duplicate Records")
duplrecform.BackColor<-Color.Beige
let ffont=new Font("Arial", 9.75F,FontStyle.Regular, GraphicsUnit.Point)
let constring = @"Data Source=MCNDESKTOP34;Initial Catalog=Employee;User ID=; Password="
let adap=new SqlDataAdapter("select * from EmployeeInformation",constring)
let duplbl=new Label(Top=0,Left=40,Width=260)
duplbl.Text<-"Records are fetched in DataTable from Database"
let remdupllbl=new Label(Top=270,Left=40,Width=280)
remdupllbl.Text<-"After Removing Duplicate Records from DataTable"
let dt=new DataTable()
adap.Fill(dt) |>ignore
let datagrid=new DataGridView(Top=20,Left=40,Width=440,Height=200)
datagrid.DataSource<-dt
let removebtn=new Button(Top=240,Left=40,Width=260)
removebtn.Text<-"Remove Duplicate Records from DataTable"
removebtn.BackColor<-Color.Ivory
duplrecform.Controls.Add(datagrid)
duplrecform.Controls.Add(removebtn)
duplrecform.Controls.Add(duplbl)
duplrecform.Controls.Add(remdupllbl)
removebtn.Click.Add(fun _->
let con = new SqlConnection(constring)
con.Open()
let com = new SqlCommand()
com.Connection <- con
com.CommandType <- CommandType.StoredProcedure
com.CommandText <- "DeleteDuplicateRecords"
let adapter = new SqlDataAdapter("DeleteDuplicateRecords",con)
let dt = new DataTable()
adapter.Fill(dt) |>ignore
let gridview = new DataGridView(Top=300,Left=40,Width=450,Height=130)
duplrecform.Controls.Add(gridview)
gridview.DataSource <- dt
)
application.Run(duplrecform)