open System
open System.Windows.Forms
open System.Drawing
open System.Data
open System.Data.SqlClient
let grpbyform=new Form(Text="Grouping the Records")
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
let datagrid=new DataGridView(Top=50,Left=0,Width=500,Height=250)
grpbyform.Controls.Add(datagrid)
let grupbylbl=new Label(Text="Group by clause",Top=270,Width=120,Left=20)
grpbyform.Controls.Add(grupbylbl)
datagrid.DataSource<-dt
let grupbtn=new Button(Top=350,Left=20,Width=120)
grupbtn.Text<-"Grouping by Name"
grupbtn.ForeColor<-Color.Red
grupbtn.BackColor<-Color.Ivory
grpbyform.Controls.Add(grupbtn)
grupbtn.Click.Add(fun _->
let com = new SqlCommand()
com.Connection <- con
com.CommandType <- CommandType.StoredProcedure
com.CommandText <- "TotalMarks"
let adapter = new SqlDataAdapter("TotalMarks",con)
let dt = new DataTable()
adapter.Fill(dt) |>ignore
let gridview = new DataGridView(Top=380,Left=20,Width=240,Height=120)
grpbyform.Controls.Add(gridview)
gridview.DataSource <- dt
)
let maxbtn=new Button(Top=350,Left=270,Width=180)
maxbtn.Text<-"Maximmum Marks by Subject"
maxbtn.BackColor<-Color.Ivory
maxbtn.ForeColor<-Color.Red
grpbyform.Controls.Add(maxbtn)
maxbtn.Click.Add(fun _->
let com = new SqlCommand()
com.Connection <- con
com.CommandType <- CommandType.StoredProcedure
com.CommandText <- "MaxMarks"
let adapter = new SqlDataAdapter("MaxMarks",con)
let dt = new DataTable()
adapter.Fill(dt) |>ignore
let gridview = new DataGridView(Top=380,Left=270,Width=240,Height=120)
grpbyform.Controls.Add(gridview)
gridview.DataSource <- dt
)
let exitbtn=new Button(Top=350,Left=470,Width=40)
exitbtn.Text<-"Exit"
exitbtn.ForeColor<-Color.Red
exitbtn.BackColor<-Color.Ivory
grpbyform.Controls.Add(exitbtn)
exitbtn.Click.Add(fun exit->
grpbyform.Close())
Application.Run(grpbyform)