Introduction: DataBinding is the most important thing when we develop any application. It is a process to map a value or set of values to a user interface control. We store data at back-end on database and transfer data to and from the front-end.
Creating DataBase: We create a DataBase
for binding. Here, in my example, the DataBase name is student_record, table name is
student and Columns are Roll_No and Name. I am using SQL server. I have written code for creating this
database. Look at the below SQL statements.
create
database student_record
use student_record
create table student
(
Roll_No int primary
key,
Name varchar(20)
)
insert into
student values(1,'Alok
Pandey')
insert into
student values(2,'Satish
Kumar')
insert into student
values(3,'Amitabh
Pandey')
insert into student
values(4,'Pramod
Sharma')
insert into student
values(5,'Durgesh
Pandey')
After creating the DataBase and table we
start to a develop F# application for DataBinding. We follow the following steps
for this.
Step 1: Take a F# application. Like the below figure
Page will look like below figure.
Step 2: We go to Solution Explorer and Right Click on References. Like
below figure.
Step 3: Click on Add References. Then a pop-up window with caption Add Reference
will open as in the below figure.
Step 4: Click at .Net on Add Reference window and select
System.Windows.Forms, System.Drawing and System.Data with
holding down Ctrl key and Click on Ok.
Step 5: Write the below F# code in the Program.fs file.
//importing
namespace
open System
open
System.Windows.Forms
open
System.Drawing
open
System.Data.SqlClient
open System.Data
// cteating connection string
let constring =
@"Data Source=Server_Name;Initial
Catalog=student_record;Integrated Security=True"
//creating DataAdapter with two parameter
//one for command string and
//another for connection string
let adapter =
new SqlDataAdapter("select
* from student",constring)
//creating DataSet
let ds =
new DataSet()
//filling the DataSet
adapter.Fill(ds) |>ignore
//creating Form
let form =
new Form()
//creating DataGridView
let gridview =
new DataGridView()
//Adding DataGridView
form.Controls.Add(gridview)
//Binding DAtaGridView to DataSet
gridview.DataSource <- ds.Tables.[0]
//Showing the form
Application.Run(form)
Step 6: Run the code by pressing Ctrl+F5 key.

Join the conversation! Your thoughts help the community grow.