You are not showing what your data table values are as per you given try this code if you are filling datagridview with datatable try this code
Form_load code
private void Form3_Load(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add("sess", typeof(int));
table.Columns.Add("crs", typeof(string));
table.Columns.Add("Fac", typeof(string));
table.Columns.Add("date", typeof(DateTime));
table.Rows.Add(25, "C#", "Dorababu", DateTime.Now);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = table;
}
Your button code
private void button1_Click(object sender, EventArgs e)
{
DateTime dt = new DateTime();
int id = 0;
string course = string.Empty;
string Faccode = string.Empty;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
id = Convert.ToInt16(dataGridView1.Rows[i].Cells["sess"].Value.ToString());
dt = Convert.ToDateTime(dataGridView1.Rows[i].Cells["date"].Value.ToString());
course = dataGridView1.Rows[i].Cells["crs"].Value.ToString();
Faccode = dataGridView1.Rows[i].Cells["Fac"].Value.ToString();
// Your database code for insert the value to database
}
}