open System
open System.Windows.Forms
open System.Drawing
open System.Data
open System.Data.SqlClient
//Create the new Window form
let havform=new Form(Text="Filter the Records")
//ConnectionString that establishes the connection with the specified database.
let constring = @"Data Source=MCNDESKTOP34;Initial Catalog=StudentResults;User ID=; Password="
let con=new SqlConnection(constring)
let com=new SqlCommand()
let adap=new SqlDataAdapter("select * from StudentMarks",constring)
let dt=new DataTable()
adap.Fill(dt) |>ignore
//DataGrid it shows the data in tabular format.
let datagrid=new DataGridView(Top=50,Left=0,Width=500,Height=250)
havform.Controls.Add(datagrid)
let grupbylbl=new Label(Text="Having Clause",Top=270,Width=120,Left=20)
havform.Controls.Add(grupbylbl)
datagrid.DataSource<-dt
let totalbtn=new Button(Top=350,Left=20,Width=220)
totalbtn.Text<-"Students Having Scored More Than 210"
totalbtn.ForeColor<-Color.Black
totalbtn.BackColor<-Color.Ivory
havform.Controls.Add(totalbtn)
totalbtn.Click.Add(fun _->
let com = new SqlCommand()
com.Connection <- con
com.CommandType <- CommandType.StoredProcedure
//ScoreHaving is a StoredProcedure it is shows the stdudent name who have scored more than 210 marks
com.CommandText <- "ScoreHaving"
let adapter = new SqlDataAdapter("ScoreHaving",con)
let dt = new DataTable()
adapter.Fill(dt) |>ignore
let gridview = new DataGridView(Top=380,Left=20,Width=240,Height=120)
havform.Controls.Add(gridview)
gridview.DataSource <- dt
)
let avgbtn=new Button(Top=510,Left=20,Width=180)
avgbtn.Text<-"Average Marks of Students"
avgbtn.BackColor<-Color.Ivory
avgbtn.ForeColor<-Color.Black
havform.Controls.Add(avgbtn)
avgbtn.Click.Add(fun _->
let com = new SqlCommand()
com.Connection <- con
com.CommandType <- CommandType.StoredProcedure
//UsingWhereCondition is a StoredProcedure it is applies for having clause using Where condtion
com.CommandText <- "UsingWhereConditon"
let adapter = new SqlDataAdapter("UsingWhereConditon",con)
let dt = new DataTable()
adapter.Fill(dt) |>ignore
let gridview = new DataGridView(Top=540,Left=20,Width=240,Height=120)
havform.Controls.Add(gridview)
gridview.DataSource <- dt
)
let exitbtn=new Button(Top=350,Left=470,Width=40)
exitbtn.Text<-"Exit"
exitbtn.ForeColor<-Color.Black
exitbtn.BackColor<-Color.Ivory
havform.Controls.Add(exitbtn)
exitbtn.Click.Add(fun exit->
havform.Close())
//Run the application
Application.Run(havform)