open System
open System.Windows.Forms
open System.Data
open System.Data.SqlClient
open System.Drawing
let constring = @"Data Source=MCNDESKTOP34;Initial Catalog=Employee;User Id=; Password="
let con = new SqlConnection(constring)
let dataadpter=new SqlDataAdapter("Select * from EmployeeSalary", con)
let dt=new DataTable()
dataadpter.Fill(dt)|>ignore
let ds = new DataSet()
dataadpter.Fill(ds,"empInfo")|>ignore
let datagrid=new DataGridView(Top=20,Left=40,Width=330,Height=180)
datagrid.DataSource<-dt
let navbuttonform = new Form(Text="Use Navigational Buttons")
//creates User controls
let lblname=new Label(Text="Employee Name:",Top=240,Left=0,Width=120)
let lblsalary=new Label(Text="Salary:",Top=280,Left=0,Width=40)
let namelabel=new Label(Top=240,Left=130,BorderStyle=BorderStyle.FixedSingle,Width=80)
let salarylabel=new Label(Top=280,Left=130,BorderStyle=BorderStyle.FixedSingle)
let bindsource=new BindingSource()
//creates a binding navigator
let navigationbind=new BindingNavigator(Dock=DockStyle.None,Top=200,Left=40)
let movefirst=new ToolStripButton(Text="Top")
let moveprev=new ToolStripButton(Text="Prev")
let movenext=new ToolStripButton(Text="Next")
let movelast=new ToolStripButton(Text="Bottom")
let exitbutton=new ToolStripButton(Text="Exit")
let Deletebutton=new ToolStripButton(Text="Delete")
navigationbind.Items.Add(movefirst)|>ignore
navigationbind.Items.Add(moveprev)|>ignore
navigationbind.Items.Add(movenext)|>ignore
navigationbind.Items.Add(movelast)|>ignore
navigationbind.Items.Add(exitbutton)|>ignore
navigationbind.Items.Add(Deletebutton)|>ignore
//funtions for the each navigational
navigationbind.MoveFirstItem<-movefirst
navigationbind.MoveNextItem<-movenext
navigationbind.MovePreviousItem<-moveprev
navigationbind.MoveLastItem<-movelast
navigationbind.DeleteItem<-Deletebutton
exitbutton.Click.Add(fun exit->
navbuttonform.Close()
con.Close())
bindsource.DataSource<-ds
bindsource.DataMember<-"empInfo"
navigationbind.BindingSource<-bindsource
con.Open()
//Binding UserControl
navbuttonform.Controls.Add(datagrid)
navbuttonform.Controls.Add(lblname)
navbuttonform.Controls.Add(lblsalary)
navbuttonform.Controls.Add(namelabel)
navbuttonform.Controls.Add(salarylabel)
navbuttonform.Controls.Add(navigationbind)
namelabel.DataBindings.Add(new Binding("Text",bindsource,"EmpName"))
salarylabel.DataBindings.Add(new Binding("Text",bindsource,"Salary"))
navbuttonform.Show()
Application.Run(navbuttonform)
In the code above I have used the "bindsource" class. The bindsource class has the ability to retrieve the data from the datasource and the datasource property has the defauult property of the bindsource class.